Created
October 15, 2019 19:08
-
-
Save isabellatea/059fa6eea717ca3e5f23a1c377402e59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class RPS { | |
public static void main(String[] args) { | |
Boolean gameActive = true; | |
String userChoice; | |
String aiChoice; | |
String result; | |
while (gameActive) { | |
//Select random number 0,1,or 2, where 0=rock, 1=paper, 2=scissor | |
int rnd = (int)(Math.random() * 3); | |
System.out.println("Play Rock (r), Paper (p), or Scissors (s)"); | |
Scanner scanner = new Scanner(System.in); | |
userChoice = scanner.nextLine(); | |
//Check Winner | |
//Tie Case | |
if (userChoice.equals("r") && rnd == 0 || ________FILL ME IN________ || ________FILL ME IN________) { | |
result = "It's a tie"; | |
} | |
//Lose Case | |
else if (________FILL ME IN________ || userChoice.equals("p") && rnd == 2 || ________FILL ME IN________) { | |
result = "You Lose!"; | |
} | |
//Win Case | |
else | |
result = "You win!"; | |
String ai = ""; | |
if(rnd == 0){ | |
ai="r"; | |
} | |
else if(rnd == 1){ | |
ai="p"; | |
} | |
else { | |
ai="s"; | |
} | |
System.out.println("You picked: " + userChoice + " and the AI picked: " + ai + ". " + result); | |
System.out.println("Do you want to play again? y / n"); | |
String restart = scanner.nextLine(); | |
if (restart.equals("N") || restart.equals("n")) { | |
gameActive = false; | |
} | |
} | |
System.exit(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool