0 members and 14,746 guests
No Members online

» Site Navigation
» Stats
Members: 35,442
Threads: 103,075
Posts: 826,688
Top Poster: cc.RadillacVIII (7,429)
|
-
JavaScript library
JavaScript library
Rock, Paper, Scissors 2
Play Rock, Paper, Scissors against your computer. Make your selection and the computer will randomly choose as well and then the game will be scored. Fun!... detail
How to setup
Step 1: Place HTML below in your BODY section
HTML
Code:
<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=0
src="rock.gif" alt="Rock"></a>
<a href="javascript:;" onClick=playGame(2);><img border=0
src="scissors.gif" alt="Scissors"></a>
<a href="javascript:;" onClick=playGame(3);><img border=0
src="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=3
NAME="loss" LOSS.VALUE="0"> Losses <INPUT TYPE="text" SIZE=2
MAXLENGTH=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 globals
var Players_Choice;
var Computers_Choice;
//pre load image onto user computer
var 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 this
Players_Choice=Choice;
// change players image
document.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 animation
clearInterval(intervalID1);
//Player won
if ( (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 draw
else if ( Players_Choice == Computers_Choice ){
tie.value++;
alert ('It is a draw'); }
// Player Lost
else {
loss.value++;
alert ('You lost'); }
}
function clear_score() {
// wipe score board
loss.value=0
win.value=0
tie.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
-->
Step 2: downloads
Files
paper1.gif
rock1.gif
scissors1.gif
 Originally Posted by Copyright
The Site may provide, or third parties may provide, links to non-JavaScriptBank.com Internet World Wide Web sites or resources. Because JavaScriptBank.com has no control over such sites and resources, you acknowledge and agree that JavaScriptBank.com is not responsible for the availability of such external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. You further acknowledge and agree that JavaScriptBank.com shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such site or resource.
Similar Threads
-
By mannos in forum Resources
Replies: 9
Last Post: 06-25-2007, 11:17 AM
-
By Akkad in forum Other Tutorials
Replies: 0
Last Post: 12-04-2006, 10:56 PM
-
By ChaosDealer73 in forum Other Tutorials
Replies: 1
Last Post: 10-20-2005, 01:17 PM
-
By 1337elite in forum Support
Replies: 0
Last Post: 06-29-2005, 03:27 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|