/** * Compares the number given with a random lucky number. If they match, the Player object will be * updated with details of the new Prize they have won. * * @param guess The number that is to be compared. */ private void compareLuckyNumber(int guess) { System.out.println("You have guessed: " + guess); int randomNumber = LuckyGuessGenerator.generateRandomNumber(prizes.getSize()); System.out.println("The lucky number is: " + randomNumber); if (guess == randomNumber) { players.getPlayer(currentPlayer).addPrize(prizes.getPrize(guess - 1)); System.out.println( "Congratulations! you have won a " + prizes.getPrize(guess - 1).getName() + " worth $" + prizes.getPrize(guess - 1).getWorth() + "!\n"); players.getPlayer(currentPlayer).addWorth(prizes.getPrize(guess - 1).getWorth()); } else System.out.println("Too bad! You didn't win anything.\n"); players.getPlayer(currentPlayer).addSpent(prizes.getPrize(guess - 1).getCost()); }
private void playFile(File file) throws Exception { player = playerList.getPlayer(playListManager.getTrackDatabase().getPlayer()); try { player.play(file); } catch (PlayerException e) { e.printStackTrace(); } finally { // Without this, RoboJock can't talk because it fights with the // Java player over the sound device. player.close(); } }
/** * 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; } } }