|
|
|
Picture Puzzle Game |
|
Put the puzzle back together again. |
|
\n' document.write(temp); var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1; var matchtowin = new Array(4); var gameboard = new Array(4); function init(){ matchtowin[0] = new Array(4); matchtowin[1] = new Array(4); matchtowin[2] = new Array(4); matchtowin[3] = new Array(4); gameboard[0] = new Array(4); gameboard[1] = new Array(4); gameboard[2] = new Array(4); gameboard[3] = new Array(4); var beenthere= new Array(16); for (x=0;x<16;++x){ beenthere[x]=0; } for (y=0;y<4;++y){ for (x=0;x<4;++x){ test=Math.round(Math.random()*15); while (beenthere[test]!=0){ test=Math.round(Math.random()*15); } beenthere[test]=1; gameboard[y][x]=test; matchtowin[y][x]=y*4+x; } } update(); } function findx(piece){ var temp=0; for (y=0;y<4;++y){ for (x=0;x<4;++x){ if (gameboard[y][x]==piece){ temp=x; } } } return temp; } function findy(piece){ var temp=0; for (y=0;y<4;++y){ for (x=0;x<4;++x){ if (gameboard[y][x]==piece){ temp=y; } } } return temp; } function move(piece){ var puzzleObj = InternetExplorer ? puzzle : document.puzzle; var movex, movey, blankx, blanky, temp, dir=0; movex=findx(piece); movey=findy(piece); blankx=findx(15); blanky=findy(15); if (movey>0){ if ((movex==blankx)&&(movey-1==blanky)){ dir=1; } } if (movex>0){ if ((movex-1==blankx)&&(movey==blanky)){ dir=2; } } if (movey<3){ if ((movex==blankx)&&(movey+1==blanky)){ dir=3; } } if (movex<3){ if ((movex+1==blankx)&&(movey==blanky)){ dir=4; } } if (dir!=0){ puzzleObj.TGotoFrame("_flash0/"+movey+movex, (((piece+1)*100)/2 + (5*dir))); puzzleObj.TPlay("_flash0/"+movey+movex); temp=gameboard[movey][movex] gameboard[movey][movex]=gameboard[blanky][blankx]; gameboard[blanky][blankx]=temp; } } function update(){ var puzzleObj = InternetExplorer ? puzzle : document.puzzle; for (y=0;y<4;++y){ for (x=0;x<4;++x){ puzzleObj.TGotoFrame("_flash0/"+y+x, ((gameboard[y][x]+1)*100)/2); } } } function puzzle_DoFSCommand(command, args) { var puzzleObj = InternetExplorer ? puzzle : document.puzzle; if (command=="slide"){ temp=parseInt(args); move(temp); } if (command=="update"){ update(); } if (command=="init"){ init(); } } //-->
|