»
EnglishFrenchVietnamese

Print - Simon Says - JavaScriptBank.com

Full version: jsB@nk » Game » Skill » Simon Says
URL: https://www.javascriptbank.com/simon-says-index.html

Simon Says © JavaScriptBank.comMemory game where you try to match 'Simon's' moves.

Full version: jsB@nk » Game » Skill » Simon Says
URL: https://www.javascriptbank.com/simon-says-index.html



CSS
<style type="text/css">body{background-color:white;font-size:10pt;font-family:sans-serif;color:#00436e;}</style><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


JavaScript
<script language="javascript">var ok=false, pcbusy=false, userturn=true, butdown=false, tst=true, stage=1, cnt=1, pcclicks=new Array(). userclicks=new Array(), pos;var btn1=new Image();btn1.src="btn1.gif";var btn2=new Image();btn2.src="btn2.gif";function updown(isdn){document.images['pl'+pos].src=(isdn)? 'btn2.gif' : 'btn1.gif';}function dopc(){document.f.st.value=stage;if(cnt<=stage){pcbusy=true;userturn=false;document.f.s.value="Simon's  Turn";setTimeout("pos=Math.floor((Math.random()*8)+1) ; updown(true)",500);setTimeout("updown(false) ; pcclicks[cnt]=pos ; cnt++ ; dopc()",1200);}else{userclicks=new Array();cnt=1;document.f.s.value="Player's  Turn";pcbusy=false;userturn=true;}}function testclicks(){tst=true;for(i=1;cnt>i;i++)tst=(pcclicks[i]==userclicks[i])? tst && true : tst && false;(tst)? setTimeout("nextlevel()",300) : setTimeout("startover()",300);cnt=1;}function nextlevel(){document.f.st.value=++stage;alert('You did it! Click "Ok" to go on to the next level.');dopc();}function startover(){stage=1;cnt=1;pcclicks=new Array();document.f.st.value=stage;alert('Sorry, You missed.\n\nClick "Ok" to start over');dopc();}function testclk(downflag,pos){if(userturn&&(!pcbusy)){document.images['pl'+pos].src=(downflag)? 'btn2.gif' : 'btn1.gif';if(ok&&!downflag){userclicks[cnt]=pos;cnt++;if(pcclicks.length==userclicks.length)testclicks();}}}window.onload=function(){var t='PLAY INSTRUCTIONS:\n\n- Simon starts the game. Remember which order he moves!.\n- When Simon is done, match his moves in the exact order.\n- An alert box will pop up telling you if you matched correctly or not.\n- The text box tells you whose turn it is.\n- Losing restarts the game at level 1, otherwise the level advances.\n- Don\'t try to cheat! Your clicks only count when it is your turn.\n\nNote:  Be sure to press AND release the mouse button while over\neach button. If you don\'t, the button will not change color the way\nit\'s supposed to.\n\nClick "Ok" to start the game...';alert(t);ok=true;dopc();}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form name="f"><table cellspacing="20" cols="5" width="600"><tr height="60"><td colspan="5" align="center"><img src="btn1.gif" name="pl1" onMousedown="testclk(true,1)" onMouseup="testclk(false,1)"></td></tr><tr height="60"><td width="20%">&nbsp;</td><td align="center" width="20%"><img src="btn1.gif" name="pl2" onMousedown="testclk(true,2)" onMouseup="testclk(false,2)"></td><td width="20%" align="center"><font size="3">Level<br></font><input type="text" size="2" value="1" name="st" readonly></td><td align="center" width="20%"><img src="btn1.gif" name="pl3" onMousedown="testclk(true,3)" onMouseup="testclk(false,3)"></td><td width="20%">&nbsp;</td></tr><tr height="60"><td align="center"><img src="btn1.gif" name="pl4" onMousedown="testclk(true,4)" onMouseup="testclk(false,4)"></td><td align="center" colspan="3"><input type="text"  name="s" value="Simon's Turn" readonly></td><td align="center"><img src="btn1.gif" name="pl5" onMousedown="testclk(true,5)" onMouseup="testclk(false,5)"></td></tr><tr height="60"><td>&nbsp;</td><td align="center"><img src="btn1.gif" name="pl6" onMousedown="testclk(true,6)" onMouseup="testclk(false,6)"></td><td>&nbsp;</td><td align="center"><img src="btn1.gif" name="pl7" onMousedown="testclk(true,7)" onMouseup="testclk(false,7)"></td><td>&nbsp;</td></tr><tr height="60"><td colspan="2">&nbsp;</td><td align="center"><img src="btn1.gif" name="pl8" onMousedown="testclk(true,8)" onMouseup="testclk(false,8)"></td><td colspan="2">&nbsp;</td></tr></table></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


Files
http://javascriptbank.com/javascript/game/Simon_Says/btn1.gifhttp://javascriptbank.com/javascript/game/Simon_Says/btn2.gif