www.webdeveloper.com
Results 1 to 4 of 4

Thread: Rock Paper Scissors

  1. #1
    Join Date
    Apr 2010
    Posts
    5

    Post Rock Paper Scissors

    First of all, hello! I'm new to this forum, and a bit of a novice at Javascript. I have written a game of rock, paper, scissors. There are two things I would like to do here:


    1. Make the playagain function work. I would like to have a variable start out as 'y', then be redefined as either 'y' or 'n' when the prompt occurs. If this is not possible, any other way to make this work would be welcome.

    2. Use <div> tags and CSS to make .swf's appear and disappear accordingly.
    EX: I say scissors, Computer says paper. An swf is played of scissors beating paper. When the anim is over, it disappears, and the game continues.

    The Code:
    Code:
    <HTML>
    
    <HEAD>
    
    <SCRIPT LANGUAGE = "JavaScript">
    
    	var mywins = 0
    
    	var compwins = 0
    
    var x = 'y'
    
    function intro(){
    
    
    	var name = prompt('What is your name?');
    
    	alert('Hello, ' + name + '!');
    
    	alert('I want to play rock, paper, scissors with you, ' + name + '.');
    
    	alert("Let's begin.");
    
    	alert("type 's' for scissors, 'r' for rock, and 'p' for paper!");
    
    }
    
    function MainLoop(){
    	var mywins = 0
    
    	var compwins = 0
    
    	while(compwins < 3 || mywins < 3){
    
    	var choice=prompt('Your turn!');
    
    	var compchoice=Math.floor(Math.random()*3);
    
    	if(choice == 'r' && compchoice == 0){
    
    		alert("That's a tie!");
    
    			}else if(choice == 'r' && compchoice == 1){
    
    			alert('I won!');
    
    			compwins = compwins + 1
    
    			}else if (choice == 'r' && compchoice == 2){
    
    			alert('You won!');
    
    			mywins = mywins + 1
    
    			}else if ( choice == 'p' && compchoice == 0){
    
    			alert('You won!');
    
    			mywins = mywins + 1
    
    			}else if (choice == 'p' && compchoice == 1){
    
    			alert('Darn! A tie!');
    
    			}else if (choice == 'p' && compchoice == 2){
    
    			alert('Haha! I picked scissors!');
    
    			compwins = compwins + 1
    
    			}else if (choice == 's' && compchoice == 0){
    
    			alert('Oh! So sad! I won that round!')
    
    			compwins = compwins + 1
    
    			}else if (choice == 's' && compchoice == 1){
    
    			alert('Ugh. I guess you won that round...');
    
    			mywins = mywins + 1
    
    			}else if (choice == 's' && compchoice == 2){
    
    			alert('A tie!')
    
    			}
    
    	alert(mywins + '-' + compwins);
    
    	if(mywins == 3 || compwins == 3){
    
    		break;
    
    		}
    
    	}
    
    }
    
    function DisplayWin(){
    
    if(compwins == 3){
    
    	alert("That's it! Three wins! I won the game! HAHA!");
    
    }else if(mywins == 3){
    
    	alert("Crap! you won! Bet you can't beat me TWICE in a row!");
    
    }
    
    }
    
    function playagain(){
    
    	var x = prompt("Play again? (y) or (n)")
    
    }
    
    </SCRIPT>
    
    </HEAD>
    
    <BODY>
    
    <SCRIPT>
    
    while(2<3){
    
    	intro();
    
    
    	MainLoop();
    
    	DisplayWin();
    
    	playagain();
    
    }
    
    </SCRIPT>
    
    </BODY>
    
    </HTML>

  2. #2
    Join Date
    Oct 2006
    Posts
    939
    I don't know how anyone can bear all those prompts, why bother with the html?
    Attached Files Attached Files

  3. #3
    Join Date
    Apr 2010
    Posts
    5
    Thanks... It's a game. The prompts are used for user input!

    Does anyone have any experience with CSS or <div>?

  4. #4
    Join Date
    Apr 2010
    Posts
    5
    Well, the game you made is nice, but I made .swf's for my game to make it a little more fun and interactive.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles