SuF
Legend
- Joined
- Jan 21, 2007
- Sythe Gold
- 1,234
- Messages
- 14,211
I threw this together during history class. Might add a simple GUI, if I am bored during history again. 
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.
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.


