• Log in or sign up for an account here: https://www.sythe.org/login

[GAME] Rock, Paper, Scissors, :P

SuF

Legend
Joined
Jan 21, 2007
Sythe Gold
1,234
Messages
14,211
[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
 
[GAME] Rock, Paper, Scissors, :P
Starting running it. Was funny ;) Then stopped on Scissors.
 
[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
 
[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

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
 
[GAME] Rock, Paper, Scissors, :P
it was fun but its messes up alot
 
[GAME] Rock, Paper, Scissors, :P
it was fun but its messes up alot

how so? i think i have a better version, but then i would have to look for it.. may post later....
 
[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

is there liek a tutorial on script stuff? I have no idea what u guys are talking about
 
[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?
 
[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?

yes it does, but i made it during history class so wha tdo you except? i think i have a better version somewhere... :P
 
Runescape Gamblingrunescape gambling
Back
Top