Phiên bản đầy đủ: jsB@nk » Trò chơi » Oẳn tù tì 2
URL: https://www.javascriptbank.com/rock-paper-scissors-index2.html
Hiệu ứng tạo trò chơi JavaScript oẳn tù tì với máy.
Phiên bản đầy đủ: jsB@nk » Trò chơi » Oẳn tù tì 2
URL: https://www.javascriptbank.com/rock-paper-scissors-index2.html
<FORM>Click on either the rock, scissors or paper to make your selection.<br>Rock beats scissors. Scissors beats paper. Paper beats rock.</p><a href="javascript:;" onClick=playGame(1);><img border=0src="rock.gif" alt="Rock"></a> <a href="javascript:;" onClick=playGame(2);><img border=0src="scissors.gif" alt="Scissors"></a> <a href="javascript:;" onClick=playGame(3);><img border=0src="paper.gif" alt="Paper"></a><br> Rock || Scissors || Paper<p><img border=0 NAME="user_image" src="rock.gif"> <img border=0 NAME="comp_image"src="paper.gif" ><br> You || Computer </p><p> <INPUT TYPE="text" SIZE=2 MAXLENGTH=3 NAME="win"WIN.VALUE="0"> Wins <INPUT TYPE="text" SIZE=2 MAXLENGTH=3NAME="loss" LOSS.VALUE="0"> Losses <INPUT TYPE="text" SIZE=2MAXLENGTH=3 NAME="tie" TIE.VALUE="0"> Ties</p><p> <input type=button value="Clear Score"onClick="clear_score()"></p></fieldset></center><SCRIPT LANGUAGE="JavaScript"><!-- Begin<!-- Hide script from old browsers// Go the globalsvar Players_Choice;var Computers_Choice;//pre load image onto user computervar imageArray = new Array(3);for (var i=0 ; i<3 ; i++)imageArray[i] = new Image();imageArray[0].src="rock.gif";imageArray[1].src="scissors.gif";imageArray[2].src="paper.gif";function playGame(Choice) {//Wouldn't work unless I did thisPlayers_Choice=Choice;// change players imagedocument.user_image.src = imageArray[Players_Choice-1].src;//Have comp's choice Change Intermitently (Animate)intervalID1 = setInterval('SwitchImage();',100);setTimeout('results(intervalID1);',700);}function SwitchImage(){Computers_Choice=(Math.round(Math.random()*2)+1);document.comp_image.src = imageArray[Computers_Choice-1].src;}function results(intervalID1) {//Firstly, Stop the animationclearInterval(intervalID1);//Player wonif ( (Players_Choice == 1 && Computers_Choice == 2) ||(Players_Choice == 2 && Computers_Choice == 3) ||(Players_Choice == 3 && Computers_Choice == 1)){win.value++;alert ('You Win'); }// Its a drawelse if ( Players_Choice == Computers_Choice ){tie.value++;alert ('It is a draw'); }// Player Lostelse {loss.value++;alert ('You lost'); }}function clear_score() {// wipe score boardloss.value=0win.value=0tie.value=0}// End --></script></form><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
http://javascriptbank.com/javascript/game/Rock_Paper_Scissors/paper1.gifhttp://javascriptbank.com/javascript/game/Rock_Paper_Scissors/rock1.gifhttp://javascriptbank.com/javascript/game/Rock_Paper_Scissors/scissors1.gif