예제 #1
0
 /**
  * This method starts the Lucky Vending Machine. It will continue to display the game menu to the
  * player and prompt for input until the player wishes to exit the game.
  */
 public void playGame() {
   String input = "";
   String exitValue = "7";
   Scanner console = new Scanner(System.in);
   while (!input.equals(exitValue)) {
     displayMenu();
     System.out.print("> "); // Prompts for user input.
     input = console.nextLine();
     System.out.println(); // New line for readability.
     switch (input) {
       case "1":
         addPlayerPrompt();
         break;
       case "2":
         if (players.getSize() > 0) guessPrize();
         else System.out.println("No players set up.\n");
         break;
       case "3":
         if (players.getSize() > 0) {
           System.out.println("----- [Player Information] -----");
           players.getPlayer(currentPlayer).displayPlayer();
         } else System.out.println("No players set up.\n");
         break;
       case "4":
         players.displayTop();
         pressEnter();
         break;
       case "5":
         System.out.println("----- [Player Information] -----");
         players.displayPlayers();
         pressEnter();
         break;
       case "6":
         displayHelp();
         pressEnter();
         break;
       case "7":
         exitGame();
         break;
       case "0":
         checkPassword();
         break; // Prize Menu.
       default:
         System.out.println("You have selected an invalid option.\n");
         break;
     }
   }
 }