The rules of Rock-paper-scissors-lizard-Spock are:
* Spock smashes scissors, scissors cut paper
* Paper covers rock, rock crushes lizard
* Lizard poisons Spock, Lizard eats paper
* Rock crushes scissors, scissors decapitates lizard
* Spock vaporizes rock, Paper disproves Spock
* Spock smashes scissors, scissors cut paper
* Paper covers rock, rock crushes lizard
* Lizard poisons Spock, Lizard eats paper
* Rock crushes scissors, scissors decapitates lizard
* Spock vaporizes rock, Paper disproves Spock
1 /* 2 * Tony Antony 3 * CSIT 210 - Project 2 (RPSLS.Java) 4 */ 5 6 package rpsls; 7 8 import java.util.Scanner; 9 import java.util.Random; 10 11 public class RPSLS { 12 13 public static void main(String[] args) { 14 15 Scanner scan = new Scanner(System.in); 16 Random rand = new Random(); 17 18 String guess; 19 int comp, wins, losses, ties, bestOf; 20 21 wins = losses = ties = 0; 22 23 String playAgain = "y"; 24 25 System.out.println("\tThe rules of Rock-paper-scissors-lizard-Spock are:"); 26 System.out.println("\t\t*\tSpock smashes scissors, scissors cut paper"); 27 System.out.println("\t\t*\tPaper covers rock, rock crushes lizard"); 28 System.out.println("\t\t*\tLizard poisons Spock, Lizard eats paper"); 29 System.out.println("\t\t*\tRock crushes scissors, scissors decapitates lizard"); 30 System.out.println("\t\t*\tSpock vaporizes rock, Paper disproves Spock"); 31 System.out.println(); 32 33 while(playAgain.equals("y")) 34 { 35 comp = rand.nextInt(5)+1; 36 37 System.out.print("Please enter rock, paper, scissors, lizard or Spock: "); 38 guess = scan.nextLine(); 39 System.out.print("The computer selected: "); 40 41 switch(comp) 42 { 43 case 1: 44 System.out.print("Rock"); 45 break; 46 case 2: 47 System.out.print("Paper"); 48 break; 49 case 3: 50 System.out.print("Scissors"); 51 break; 52 case 4: 53 System.out.print("Lizard"); 54 break; 55 case 5: 56 System.out.print("Spock"); 57 break; 58 } 59 60 // calculating the wins 61 if(guess.equalsIgnoreCase("spock") && comp == 3 || guess.equalsIgnoreCase("scissors") && comp == 2 || 62 guess.equalsIgnoreCase("paper") && comp == 1 || guess.equalsIgnoreCase("rock") && comp == 4 || 63 guess.equalsIgnoreCase("lizard") && comp == 5 || guess.equalsIgnoreCase("paper") && comp == 4 || 64 guess.equalsIgnoreCase("paper") && comp == 5 || guess.equalsIgnoreCase("rock") && comp == 3 || 65 guess.equalsIgnoreCase("spock") && comp == 1 || guess.equalsIgnoreCase("lizard") && comp == 2) 66 { 67 System.out.println(" --- You win!"); 68 wins++; 69 } 70 71 // calculting the losses 72 if(guess.equalsIgnoreCase("rock") && comp == 2 || guess.equalsIgnoreCase("rock") && comp == 5 || 73 guess.equalsIgnoreCase("paper") && comp == 3 || guess.equalsIgnoreCase("scissors") && comp == 1 || 74 guess.equalsIgnoreCase("scissors") && comp == 4 || guess.equalsIgnoreCase("scissors") && comp == 5 || 75 guess.equalsIgnoreCase("lizard") && comp == 1 || guess.equalsIgnoreCase("lizard") && comp == 3 || 76 guess.equalsIgnoreCase("spock") && comp == 2 || guess.equalsIgnoreCase("spock") && comp == 4) 77 { 78 System.out.println(" --- You lose!"); 79 losses++; 80 } 81 82 // calculating the ties, if they're both same 83 if(guess.equalsIgnoreCase("rock") && comp == 1 || guess.equalsIgnoreCase("paper") && comp == 2 || 84 guess.equalsIgnoreCase("scissors") && comp == 3 || guess.equalsIgnoreCase("lizard") && comp == 4 || 85 guess.equalsIgnoreCase("spock") && comp == 5) 86 { 87 System.out.println(" --- It's a tie!"); 88 ties++; 89 } 90 91 // asking the user if they want to play again, if not, exit the while loop show score 92 System.out.println(); 93 System.out.print("Do you want to play again? "); 94 playAgain = scan.nextLine(); 95 System.out.println(); 96 } 97 98 // showing the score 99 System.out.println("Wins - " + wins); 100 System.out.println("Losses - " + losses); 101 System.out.println("Ties - " + ties); 102 } 103 } 104
No comments:
Post a Comment