»
EnglishFrenchVietnamese

Print - Sticks game - JavaScriptBank.com

Full version: jsB@nk » Game » Sticks game
URL: https://www.javascriptbank.com/sticks-game.html

Sticks game © JavaScriptBank.comChoose the sticks in the proper order to win the game.

Full version: jsB@nk » Game » Sticks game
URL: https://www.javascriptbank.com/sticks-game.html



JavaScript
<SCRIPT>   var maxCount=Math.floor((screen.availWidth-25)/25);   var Count=maxCount;   //   Count=  Write your own number here      var Colors = new Array("cyan","red","green","blue","magenta","yellow");   var Box=new Array();   var CountTook=0, MCT=3; //MCT - MaxCountTook   var size=Math.floor(screen.availWidth/(Count+1))-5;   var offset=size+5;   var x0=(size-3)/2, y0=500;    function PaintButton(bool)     { if (bool) {  ButtonTake.style.backgroundColor = "lime";  ButtonTake.style.cursor = "hand";   }      else  {  ButtonTake.style.backgroundColor = "gray";  ButtonTake.style.cursor = "default";   }     }    function Mv(n, Down, id, hide)     {  Element = document.all["d"+id];  if (Down) Element.style.posTop = y0+n;  else Element.style.posTop = y0+30-n;  if (n < 30) setTimeout("Mv("+(n+5)+", "+Down+", "+id+", "+hide+")", 0);  else if (hide) Hide(id);     }    function Move(id)     { currElement = document.all["d"+id]; if (Box[id] == 0)  {   if (CountTook < MCT)    {     if (CountTook == 0) PaintButton(true);     CountTook++;     TextSelected.innerText = CountTook;     Box[id] = 1;     Mv(0, true, id, false);    }        else alert("Too many!");  }       else if (Box[id] == 1)  {   CountTook--;   TextSelected.innerText = CountTook;   if (CountTook == 0) PaintButton(false);   Box[id] = 0;   Mv(0, false, id, false);  }     }    function Hide(id)     {  Box[id] = 2;  Element = document.all["d"+id];      Element.style.visibility = "hidden";     }    function EndGame(bool)     {  alert("Game over");     }          function Take()     {  if (CountTook > 0)   {for (i=0; i<BeginCount; i++) if (Box[i] == 1) Hide(i);PaintButton(false);Count -= CountTook;CountTook = 0;TextSelected.innerText = "0";TextCount.innerText = Count;if (Count == 0) EndGame(false); else Turn();       }     }    function Turn()     {  if (Count % (MCT+1) == 1) CountTook = Math.round(Math.random()*(MCT-1))+1;  else CountTook = (Count % (MCT+1))==0 ? MCT:(Count % (MCT+1))-1;  if (CountTook > Count) CountTook = Count;  CountDeleted = 0;      i = 0;  while (CountDeleted < CountTook)  {   if (Box[i] == 0){ Mv(0, true, i, true); CountDeleted++;}   i++;  }  Count -= CountTook;  CountTook = 0;  TextCount.innerText = Count;  if (Count == 0) EndGame(true);       } </SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<DIV id=Tab style="POSITION: absolute; TOP: 5px; BACKGROUND-COLOR: gray"></DIV><DIV id=TableDiv style="POSITION: relative; left: 0; TOP: 200px"><TABLE cellSpacing=1 cellPadding=1 width="100%" border=1>  <TBODY>  <TR>    <TD align=right><STRONG>Remaining:</STRONG></TD>    <TD id=TextCount></TD>    <TD align=right><STRONG>Choesen:</STRONG></TD>    <TD id=TextSelected></TD></TR></TBODY></TABLE><TABLE cellSpacing=1 cellPadding=1 width="100%" border=1>  <TBODY>  <TR>    <TD id=ButtonTake     style="FONT-WEIGHT: bold; FONT-SIZE: large; CURSOR: default; FONT-FAMILY: cursive; BACKGROUND-COLOR: gray"     onclick=Take() align=middle>Take it</TD></TR></TBODY></TABLE><TABLE cellSpacing=1 cellPadding=1 width="100%" border=1>  <TBODY>  <TR>    <TD     style="FONT-WEIGHT: bold; FONT-SIZE: large; CURSOR: default; FONT-FAMILY: cursive; BACKGROUND-COLOR: gray"     align=middle><A href="javascript:location.reload()">Try again!!!</A></TD></TR></TBODY></TABLE></DIV><SCRIPT>     TextCount.innerText=Count;     TextSelected.innerText="0";     BeginCount=Count;     Tab.style.posHeight=200;     for (i=0; i<Count; i++)      {   document.write('<DIV Id=d'+i+' name=d'+i+' onclick=Move('+i+') Style="POSITION:absolute; CURSOR:hand; LEFT:'+((i*offset)+x0)+'px; TOP:'+y0+'px; WIDTH:'+size+'px; HEIGHT:150px; BACKGROUND-COLOR:'+Colors[i%6]+'"></DIV>');   Box[i] = 0;      }   </SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->