[GAME] Rock, Paper, Scissors, :P

Discussion in 'Programming General' started by SuF, Apr 26, 2008.

[GAME] Rock, Paper, Scissors, :P
  1. Unread #1 - Apr 26, 2008 at 9:12 PM
  2. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    [GAME] Rock, Paper, Scissors, :P

    I threw this together during history class. Might add a simple GUI, if I am bored during history again. :D

    Code:
    import java.util.*;
    
    public class RPS
    {
    
        public static void main(String[] args)
        {
    	int d = 0;
    	int e = 0;
    	System.out.println("Welcome to Rock, Paper, Sissors!");
    	System.out.println("");
    	while(true)
    	{
    	int c = pick();
    	int b = random(1, 3);
    	if(b == 1)
    	{
    	    if(c == 1)
    	    {
    		System.out.println("Its a tie! You both chose rock!");
    	    }
    	    else if(c == 2)
    	    {
    		System.out.println("The computer picked rock, and the you picked scissors. The computer wins!");
    		e++;
    	    }
    	    else if(c == 3)
    	    {
    		System.out.println("The computer picked rock, and the you picked paper. You win!");
    		d++;
    	    }
    	}
    	else if(b == 2)
    	{
    	    if(c == 2)
    	    {
    		System.out.println("Its a tie! You both chose scissors!");
    	    }
    	    else if(c == 1)
    	    {
    		System.out.println("The computer picked scissors, and the you picked rock. You win!");
    		d++;
    	    }
    	    else if(c == 3)
    	    {
    		System.out.println("The computer picked scissors, and the you picked paper. The computer wins!");
    		e++;
    	    }
    	}
    	else if(b == 3)
    	{
    	    if(c == 3)
    	    {
    		System.out.println("Its a tie! You both chose paper!");
    	    }
    	    else if(c == 1)
    	    {
    		System.out.println("The computer picked paper, and the you picked rock. The computer wins!");
    		e++;
    	    }
    	    else if(c == 2)
    	    {
    		System.out.println("The computer picked paper, and the you picked scissors. You win!");
    		d++;
    	    }
    	}
    	if(d == 3)
    	{
    	    System.out.println("");
    	    System.out.println("You won the round!");
    	    System.out.println("Starting a new round!");
    	    System.out.println("");
    	    d = 0;
    	    e = 0;
    	}
    	if(e == 3)
    	{
    	    System.out.println("");
    	    System.out.println("The computer won the round!");
    	    System.out.println("Starting a new round!");
    	    System.out.println("");
    	    d = 0;
    	    e = 0;
    	}
    	}
        }
    
        private static int pick()
        {
    	Scanner a = new Scanner(System.in);
    	System.out.print("Please choose: Rock (1), Sissors (2), or Paper (3): ");
    	while (true)
    	{
    	    try
    	    {
    		int pick = a.nextInt();
    		if(pick > 3 || pick < 1)
    		{
    		    System.out.print("Please choose: Rock (1), Sissors (2), or Paper (3): ");
    		}
    		else
    		{
    		    return pick;
    		}
    	    }
    	    catch (InputMismatchException e)
    	    {
    		a.next();
    		System.out.print("Please choose: Rock (1), Sissors (2), or Paper (3): ");
    	    }
    	}
    
        }
    
        private static int random(int min, int max)
        {
    	return (int) (Math.random() * (max - min + 1)) + min;
        }
    }
    Yes, I know I could use less code to do the same shit, but I made it during history class, and it works just fine. :p
     
  3. Unread #2 - Apr 28, 2008 at 12:08 PM
  4. Kin Kong
    Joined:
    Feb 4, 2008
    Posts:
    356
    Referrals:
    0
    Sythe Gold:
    0

    Kin Kong Forum Addict
    Banned

    [GAME] Rock, Paper, Scissors, :P

    Starting running it. Was funny ;) Then stopped on Scissors.
     
  5. Unread #3 - Apr 28, 2008 at 9:10 PM
  6. crapkiller
    Joined:
    Jul 19, 2006
    Posts:
    426
    Referrals:
    0
    Sythe Gold:
    0

    crapkiller Forum Addict

    [GAME] Rock, Paper, Scissors, :P

    Why does history have to be so boring? Unfortunately for me, if i don't pay attention during history, i will fail, which i don't want.

    Make me a tick-tack-toe with GUI so i can examine the code :D
     
  7. Unread #4 - Apr 30, 2008 at 6:54 PM
  8. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    [GAME] Rock, Paper, Scissors, :P

    maybe i will make a console version first... lol... i have not had history is about a week due to the school cancellign classes and shit ;O
     
  9. Unread #5 - Jun 18, 2008 at 12:25 PM
  10. king phat
    Joined:
    Aug 8, 2007
    Posts:
    182
    Referrals:
    0
    Sythe Gold:
    0

    king phat Active Member
    Banned

    [GAME] Rock, Paper, Scissors, :P

    it was fun but its messes up alot
     
  11. Unread #6 - Jun 18, 2008 at 8:33 PM
  12. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    [GAME] Rock, Paper, Scissors, :P

    how so? i think i have a better version, but then i would have to look for it.. may post later....
     
  13. Unread #7 - Jun 18, 2008 at 8:50 PM
  14. Benyamica
    Joined:
    Dec 1, 2007
    Posts:
    479
    Referrals:
    1
    Sythe Gold:
    0

    Benyamica Forum Addict
    Banned

    [GAME] Rock, Paper, Scissors, :P

    is there liek a tutorial on script stuff? I have no idea what u guys are talking about
     
  15. Unread #8 - Jun 18, 2008 at 11:07 PM
  16. cp
    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0

    cp an cat
    Banned

    [GAME] Rock, Paper, Scissors, :P

    If you do not understand Java, it would be wise for you to learn it.

    Google some Java tutorials or something.
    =
    I don't know if this exists in Java, but maybe you could use switch/case to simplify your code and even save you some trouble?
     
  17. Unread #9 - Jun 19, 2008 at 8:58 AM
  18. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    [GAME] Rock, Paper, Scissors, :P

    yes it does, but i made it during history class so wha tdo you except? i think i have a better version somewhere... :p
     
< Visual Basic download here! (Other Link's Don't Work? Try it here!) | Freee *hit@@@@@ >

Users viewing this thread
1 guest


 
 
Adblock breaks this site