vt=window.document.location.href; l=vt.length; vid=vt.substring(l-9,l-4); var tfieldsize=42; //needs to be an even number var numberofpairs=tfieldsize/2 var field_contains_piece = new Array(tfieldsize+5); var foundnumberofpairs=0; var first=0 var second=0 var moves=0 var UcantMove=false var Cantstart=true var countdown; var countdownTimer; for (n=1;n < (tfieldsize+1);n++) { field_contains_piece[n]=Math.floor(n/2+0.5) } function pic_is(imgname) { if (!(document.images)) { return "bad browser"; } // eval("fn=window.document.playfield.p"+imgname+".src") fn=document.images["p"+imgname].src l=fn.length filename=fn.substring(l-5,l) return filename } function renderCountdown() { var digit, blanking, tmp; blanking = true; tmp = countdown; digit = Math.floor(tmp / 1000); tmp = tmp - (digit * 1000); if(digit != 0 || !blanking) { blanking = false; document.images['ctr3'].src = "images/digits/"+digit+".jpg"; } digit = Math.floor(tmp / 100); tmp = tmp - (digit * 100); if(digit != 0 || !blanking) { blanking = false; document.images['ctr2'].src = "images/digits/"+digit+".jpg"; } digit = Math.floor(tmp / 10); tmp = tmp - (digit * 10); if(digit != 0 || !blanking) { blanking = false; document.images['ctr1'].src = "images/digits/"+digit+".jpg"; } digit = tmp; document.images['ctr0'].src = "images/digits/"+digit+".jpg"; } function doCountdown() { if(countdownTimer) { clearTimeout(countdownTimer); countdownTimer = 0; } if(countdown) { countdown--; renderCountdown(); countdownTimer = setTimeout("doCountdown()", 100); } else { gameover(); } } function display_piece(piec) { eval("window.document.playfield.p" +piec+".src='images/"+field_contains_piece[piec]+".gif'") } function hide_piece(piec) { eval("window.document.playfield.p"+piec+".src='images/0.jpg'") } function hide() { UcantMove=false hide_piece(first) hide_piece(second) second=0 first=0 } function clickon(field) { if (UcantMove ||Cantstart) return; if (!(pic_is(field)=="0.jpg")) return; display_piece(field) if (first==0 || field==first) { first=field; return; } UcantMove=true second=field moves++ if(field_contains_piece[first]!=field_contains_piece[second]) { setTimeout("hide()",1500) return; } first=0 second=0 foundnumberofpairs++ if (foundnumberofpairs==numberofpairs) { gameover(); } UcantMove=false } function gameover() { clearTimeout(countdownTimer); countdownTimer = 0; window.open("HighScoreNew.php?gamename=memory&score="+countdown, "HighScore","Width=300,Height=400"); } function randomise() { var tmp, swaptemp; for (n=1;n<(tfieldsize+1);n++) { tmp=Math.floor(Math.random()*tfieldsize+1) swaptemp=field_contains_piece[tmp]; field_contains_piece[tmp]=field_contains_piece[n]; field_contains_piece[n]=swaptemp; } } function newgame() { foundnumberofpairs=0; //reset in init countdown = 2111; doCountdown(); first=0 second=0 moves=0 for (n=1;n<(tfieldsize+1);n++) { field_contains_piece[n]=Math.floor(n/2+0.5); hide_piece(n); } randomise() Cantstart=false UcantMove=false var msg msg = "Welcome to Memory! Can you find all the pairs?\n" msg = msg + "Click OK to find out!" alert(msg); } a = new Image(80, 80) a.src="images/0.jpg" b = new Image(80, 80) b.src="images/1.gif" c = new Image(80, 80) c.src="images/2.gif" d = new Image(80, 80) d.src="images/3.gif" e = new Image(80, 80) e.src="images/4.gif" f = new Image(80, 80) f.src="images/5.gif" g = new Image(80, 80) g.src="images/6.gif" h = new Image(80, 80) h.src="images/7.gif" i = new Image(80, 80) i.src="images/8.gif" j = new Image(80, 80) j.src="images/9.gif" k = new Image(80, 80) k.src="images/10.gif" l = new Image(80, 80) l.src="images/11.gif" m = new Image(80, 80) m.src="images/12.gif" n = new Image(80, 80) n.src="images/13.gif" o = new Image(80, 80) o.src="images/14.gif" p = new Image(80, 80) o.src="images/15.gif" q = new Image(80, 80) q.src="images/16.gif" r = new Image(80, 80) r.src="images/17.gif" s = new Image(80, 80) s.src="images/18.gif" t = new Image(80, 80) t.src="images/19.gif" u = new Image(80, 80) u.src="images/20.gif" v = new Image(80, 80) v.src="images/21.gif" w = new Image(80, 80) w.src="images/22.gif" x = new Image(80, 80) x.src="images/23.gif" y = new Image(80, 80) y.src="images/24.gif"