Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.53 KB | None | 0 0
  1. package XeroCodeTest;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Scanner;
  5. import java.util.InputMismatchException;
  6.  
  7. public class FirmentRockPaperScissors {
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         // NICK - this block of comments will not be in the finished code. I'm
  12.         // having trouble with the first one, putting stuff outside of Main
  13.  
  14.         // TO DO - Try to put the hashmap stuff outside of Main. Put as much as
  15.         // possible outside of Main.
  16.  
  17.         // Create an install guide.
  18.  
  19.         // Create a design document explaining what it is, and what I wish it
  20.         // could be in the future.
  21.  
  22.         String[] options = { "Rock", "Paper", "Scissors" };
  23.  
  24.         HashMap<String, String> outcomes = new HashMap<String, String>();
  25.         outcomes.put("RockRock", "Tie. The two Rocks bump against each other.");
  26.         outcomes.put("RockPaper",
  27.                 "Computer wins. Sorry, the computer won by wrapping Paper around your Rock.");
  28.         outcomes.put("RockScissors",
  29.                 "You win! Your Rock smashed the computer's Scissors.!");
  30.         outcomes.put("ScissorsRock",
  31.                 "Computer wins. Your Scissors are blunted by the computer's Rock.");
  32.         outcomes.put("ScissorsPaper",
  33.                 "You win! Your Scissors cut the computer's Paper neatly in half.");
  34.         outcomes.put("ScissorsScissors",
  35.                 "Tie. Like master swordsmen, the two pairs of Scissors dueled to a tie.");
  36.         outcomes.put("PaperRock",
  37.                 "You win! Your Paper wraps around Rock. You win!");
  38.         outcomes.put(
  39.                 "PaperPaper",
  40.                 "\n\nTwo Papers slide past\nPages flutter in the breeze\nThis game is a tie\n\n");
  41.         outcomes.put("PaperScissors",
  42.                 "Computer wins. The computer cuts your paper in half using Scissors.");
  43.  
  44.         int randomComputer = (int) (Math.random() * 2); // Computer chooses
  45.  
  46.         System.out.println("Let's play Rock, Paper, or Scissors.");
  47.         System.out
  48.                 .println("TELL THEM HOW TO PLAY HERE. ALSO INCLUDE HOW TO PLAY IN THE DESIGN DOC. ");
  49.         // QA Cheat Mode
  50.         // System.out.println("(Pssst. The computer has chosen " +
  51.         // options[randomComputer] + ".)");
  52.         System.out.println();
  53.         System.out.println("Would you like to use Rock, Paper, or Scissors?");
  54.         System.out
  55.                 .println("Make your selection then press [Enter]. Rock = 0, Paper = 1, Scissors = 2.");
  56.  
  57.         try {
  58.             Scanner myScanner = new Scanner(System.in);
  59.             int randomUser = myScanner.nextInt();
  60.             String chosen = options[randomUser];
  61.             System.out
  62.                     .print("You have chosen "
  63.                             + chosen
  64.                             + ". \nWhen you are ready, type GO then press [Enter] to throw. Ready?");
  65.             String x = myScanner.next(); // FUTURE TO DO - allow the user to
  66.                                             // press
  67.                                             // any key to continue.
  68.  
  69.             String result = options[randomUser] + options[randomComputer]; // Create
  70.                                                                             // the
  71.                                                                             // hashmap
  72.                                                                             // key
  73.             System.out.println("You chose " + options[randomUser]
  74.                     + " and the computer chose " + options[randomComputer]
  75.                     + ".");
  76.             System.out.println(outcomes.get(result)); // Display win/lose
  77.                                                         // information
  78.             myScanner.close();
  79.         } catch (InputMismatchException e) {
  80.             System.out
  81.                     .print("The game has ended because a non-integer value was entered. \n"
  82.                             + "During your next game, please enter an integer between 0 and 2.");
  83.             System.exit(1);
  84.         } catch (ArrayIndexOutOfBoundsException e) {
  85.             System.out
  86.                     .print("The game has ended because an integer that is not 0, 1 or 2 was entered. \n"
  87.                             + "During your next game, please enter an integer between 0 and 2.");
  88.             System.exit(2);
  89.         }
  90.  
  91.     }
  92. }
  93.  
  94. // FUTURE TO DO Do not require Enter after inputs.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement