var w,h,ratio,i,s,el,g,div,dragQ,game,my={};function marblesMain(){console.log("put stuff in here");} var INVALID=0,MARBLE=1,HOLE=2;var a=new Array(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,1,1,1,2,1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0);var b=new Array();var marbles_left=32;var currcell=-1;var gintervalid=-1,gtime=0;var game_over=true;function tick(){elapsed.innerHTML=gtime+" sec"+(gtime==1?"":"s");gtime++;} function copyArray(src,dest){for(var ii=0;ii5)?msgs[0]:msgs[marbles_left])+"\n\n"+ "No. of marbles left: "+marbles_left+"\n"+ "Time Elapsed: "+gtime+" secs");gtime=0;}} function canMove(n){if(b[n]!=MARBLE)return false;return(b[n-2]==HOLE&&b[n-1]==MARBLE)||(b[n+2]==HOLE&&b[n+1]==MARBLE)||(b[n-18]==HOLE&&b[n-9]==MARBLE)||(b[n+18]==HOLE&&b[n+9]==MARBLE);} function isGameOver(){var moveable=false;for(y=1;y<8;y++) for(x=1;x<8;x++) if(canMove(y*9+x))return false;return true;} function hit(n){if(gintervalid==-1) {gintervalid=setInterval("tick()",1000);tick();newbut.value="S T O P !";} if(b[n]==MARBLE){if(currcell!=-1)setMarble(currcell);setHilite(n);currcell=n;} if(b[n]==HOLE){if(currcell==-1){alert("Please select a marble to move");return;} if(currcell-n==2)move(currcell,n+1,n);else if(n-currcell==2)move(currcell,n-1,n);else if(n-currcell==18)move(currcell,n-9,n);else if(currcell-n==18)move(currcell,n+9,n);else alert("Sorry. Invalid move!\n\n"+ "You can move the selected marble only to\n"+ "a hole that is exactly one marble away.\n\n"+ "Diagonal moves are not allowed.");}} function dropped(){var imgid=document.elementFromPoint(event.clientX,event.clientY).id;var d=imgid.match(/c(\d+)/);if(d!=null)hit(parseInt(d[1]));} function newGame(){if(gintervalid==-1) {if(game_over||(gtime!=0&&!confirm("Do you wish to continue with the old game?\n\nClick 'Cancel' to start a new game."))){gtime=0;boardarea.innerHTML=drawBoard();game_over=false;} gintervalid=setInterval("tick()",1000);tick();newbut.value="S T O P !";}else {clearInterval(gintervalid);gintervalid=-1;newbut.value="S T A R T";}} function drawBoard(){var i,x,y,s,func;copyArray(a,b);marbles_left=32;s='';for(y=1;y<8;y++){s+='';for(x=1;x<8;x++){i=y*9+x;func='onmousedown="hit('+i+')" ondragend="dropped()" ';if(i==10||i==16||i==55||i==60){s+='";}else if(b[i]!=INVALID){s+='";}} s+="";} s+="
';if(i==60){s+=""+ ""+ ""+ "
Marbles Left:
32/32
 
"+ ""+ "
";} s+="
';if(b[i]==MARBLE)s+='';if(b[i]==HOLE)s+='';s+="
";return s;}