while (true) {
try {
System.out.println("Choose a player or type quit: Nirvaan(" + player1.getMoney() + ") or Faris(" + player2.getMoney() + ")");
String chosenPlayer = scanner.nextLine();
if (chosenPlayer.equalsIgnoreCase("quit")) {
break;
}
Player player = null;
if (chosenPlayer.equalsIgnoreCase(player1.getName())) {
player = player1;
} else if (chosenPlayer.equalsIgnoreCase(player2.getName())) {
player = player2;
}
System.out.println("Which game would " + player.getName() + " like to play? ");
System.out.println("1. Balloon Darts");
System.out.println("2. Ring Toss");
System.out.println("3. Break a Plate");
System.out.println("4. Quit");
System.out.print("> ");
int choice = scanner.nextInt();
// Check if the user chose to quit
if (choice == 4) {
break;
}
// Get the chosen game
GameBooth game = games.get(choice - 1);
// Let the players play the game
System.out.println(player.getName() + " goes to " + game.getName());
game.playGame(player);
} catch (Exception e) {
}
}
OUTPUT//
Choose a player or type quit: Nirvaan(5.0) or Faris(3.0)
nirvaan
Which game would Nirvaan like to play?
1. Balloon Darts
2. Ring Toss
3. Break a Plate
4. Quit
> 1
Nirvaan goes to Balloon Darts
Nirvaan won a Sticker
Choose a player or type quit: Nirvaan(3.0) or Faris(3.0)
Choose a player or type quit: Nirvaan(3.0) or Faris(3.0)
I tried moving the choose player line out of the try statment but that did not work, it kept on doing the same thing.