|
|
|
|
|
|
|
|
import java.util.Random; |
|
|
import java.util.Random; |
|
|
|
|
|
|
|
|
public class RockPaperScissors { |
|
|
public class RockPaperScissors { |
|
|
|
|
|
static int computerScore = 0; |
|
|
|
|
|
static int playerScore = 0; |
|
|
|
|
|
|
|
|
public static void runGame() { |
|
|
public static void runGame() { |
|
|
int computerInput = letComputerChoose(); |
|
|
int computerInput = letComputerChoose(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void checkResults(int computerInput, int userInput) { |
|
|
public static void checkResults(int computerInput, int userInput) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (computerInput == userInput) { |
|
|
if (computerInput == userInput) { |
|
|
System.out.println("Draw!"); |
|
|
System.out.println("Draw!"); |
|
|
} else if (computerInput == 1 && userInput == 2 |
|
|
} else if (computerInput == 1 && userInput == 2 |
|
|
|| computerInput == 2 && userInput == 3 |
|
|
|| computerInput == 2 && userInput == 3 |
|
|
|| computerInput == 3 && userInput == 1) { |
|
|
|| computerInput == 3 && userInput == 1) { |
|
|
|
|
|
playerScore = playerScore + 1; |
|
|
System.out.println("You win!"); |
|
|
System.out.println("You win!"); |
|
|
|
|
|
|
|
|
} else if (computerInput == 2 && userInput == 1 |
|
|
} else if (computerInput == 2 && userInput == 1 |
|
|
|| computerInput == 3 && userInput == 2 |
|
|
|| computerInput == 3 && userInput == 2 |
|
|
|| computerInput == 1 && userInput == 3) { |
|
|
|| computerInput == 1 && userInput == 3) { |
|
|
|
|
|
computerScore = computerScore + 1; |
|
|
System.out.println("Computer wins!"); |
|
|
System.out.println("Computer wins!"); |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
System.out.println("Incorrect inputs: round void"); |
|
|
System.out.println("Incorrect inputs: round void"); |
|
|
} |
|
|
} |
|
|
|
|
|
System.out.println("The score is: " + playerScore + ":" + computerScore); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static String convertToWordUser(int userInput) { |
|
|
private static String convertToWordUser(int userInput) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static int letComputerChoose() { |
|
|
public static int letComputerChoose() { |
|
|
Random rgen = new Random(); |
|
|
Random rgen = new Random(); |
|
|
int computerInput = rgen.nextInt(1, 3); |
|
|
|
|
|
|
|
|
int computerInput = rgen.nextInt(1,3); |
|
|
return computerInput; |
|
|
return computerInput; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |