var i,s,w,my={};var gsize,ghrow,ghcol,gtime,gmoves,gintervalid=-1,gshuffling;function arrangeMain(){my.version=0.7;var s='';s+='';s+='
';s+='
'
s+='Choose Level: ';s+='';s+=' ';s+='';s+='
'
s+='';s+=' ';s+='
';s+='
';s+='
';s+='
';s+='
';s+='Instructions:';s+='';s+='
Choose a Level (3 to 10).
';s+='
The game board has blocks with numbers in it. Also there is a single "hole" that can be used for moving the blocks.
';s+='
The objective of the game is to order the numbers using the "hole" for temporary movement.
';s+='
Move blocks in a row by clicking on them. A block can be moved only if it is in the same row or column as the "hole".
';s+='
You can move multiple blocks (in the same row or column as the "hole") by clicking the farthest block that you need to be moved.
';s+='';s+='
';s+='
';s+=optPopHTML();document.write(s);loadBoard(parseInt(document.getElementById('level').value));startGame();}
function toggleHelp(){if(butHelp.value=="Hide Help"){help.style.display="none";butHelp.value="Show Help";}else{help.style.display="";butHelp.value="Hide Help";}}
function r(low,hi){return Math.floor((hi-low)*Math.random()+low);}
function r1(hi){return Math.floor((hi-1)*Math.random()+1);}
function r0(hi){return Math.floor((hi)*Math.random());}
function startGame(){shuffle();gtime=0;gmoves=0;window.clearInterval(gintervalid);tickTime();gintervalid=window.setInterval("tickTime()",1000);}
function stopGame(){if(gintervalid==-1)return;window.clearInterval(gintervalid);var f=document.getElementById("fldStatus");f.innerHTML="";gintervalid=-1;}
function tickTime(){showStatus();gtime++;}
function checkWin(){var i,j,s;if(gintervalid==-1)return;if(!isHole(gsize-1,gsize-1))return;for(i=0;i";s+="
Well Done !
";s+="
You did it in "+gtime+" secs ";s+="with "+gmoves+" moves!
";s+="
Your speed is "+Math.round(1000*gmoves/gtime)/1000+" moves/sec
";s+="";var f=document.getElementById("fldStatus");f.innerHTML=s;window.clearInterval(gintervalid);}
function showStatus(){var f=document.getElementById("fldStatus");f.innerHTML="Time: "+gtime+" secs Moves: "+gmoves}
function brdGet(){var i,j,s;stopGame();s='';for(i=0;i';}
s+=' ';}
return s;}
function getCell(row,col){var s;s="a_"+row+"_"+col;return document.getElementById(s);}
function setValue(row,col,val){var v=getCell(row,col);v.value=val;v.className="cell";}
function getValue(row,col){var v=getCell(row,col);return v.value;}
function setHole(row,col){var v=getCell(row,col);v.value=" ";v.className="hole";ghrow=row;ghcol=col;}
function getRow(obj){var a=obj.id.split("_");return a[1];}
function getCol(obj){var a=obj.id.split("_");return a[2];}
function isHole(row,col){return(row==ghrow&&col==ghcol)?true:false;}
function getHoleInRow(row){var i;return(row==ghrow)?ghcol:-1;}
function getHoleInCol(col){var i;return(col==ghcol)?ghrow:-1;}
function shiftHoleRow(src,dest,row){var i;src=parseInt(src);dest=parseInt(dest);if(srcdest;i--){setValue(row,i,getValue(row,i-1));setHole(row,i-1);}}}
function shiftHoleCol(src,dest,col){var i;src=parseInt(src);dest=parseInt(dest);if(srcdest;i--){setValue(i,col,getValue(i-1,col));setHole(i-1,col);}}}
function move(obj){var r,c,hr,hc;if(gintervalid==-1&&!gshuffling){alert('Please press the "Start Game" button to start.')
return;}
r=getRow(obj);c=getCol(obj);if(isHole(r,c))return;hc=getHoleInRow(r);if(hc!=-1){shiftHoleRow(hc,c,r);gmoves++;checkWin();return;}
hr=getHoleInCol(c);if(hr!=-1){shiftHoleCol(hr,r,c);gmoves++;checkWin();return;}}
function shuffle(){var t,i,j,s,frac;gshuffling=true;frac=100.0/(gsize*(gsize+10));for(i=0;i';s+='
';s+='
';s+='Success!';s+='
';s+='
';s+='You have done it!';s+='
';s+='
';s+='Play Again?';s+='
';s+='
';s+='
';s+='';s+='';s+='
';s+='';return s;}
function optPop(){var wd=300;var ht=100;var pop=document.getElementById('optpop');pop.style.transitionDuration="0.3s";pop.style.opacity=1;pop.style.zIndex=100;var width=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width;var height=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;pop.style.left=((width/2)-(wd/2))+'px';pop.style.top=((height/2)-(ht/2)+50)+'px';}
function optYes(){var pop=document.getElementById('optpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-999px';createBlocks();}
function optNo(){var pop=document.getElementById('optpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-999px';quitGame();}