Я столкнулся с проблемой, когда, если пользователь захочет снова играть в игру, он не будет запрашивать у пользователя ввод цифр, вместо этого он будет печатать утверждения, и мне интересно, почему это происходит ...Он отлично работает, если пользователь введет «Нет», и игра закончится.Я предоставлю вам снимок, чтобы вы могли лучше понять, в чем заключается моя проблема.
import java.util.Scanner;
import java.util.*;
public class Moropinzee
{
public static void main(String[] args) {
int Monkey = 1;
int Robot = 2;
int Pirate = 3;
int Ninja = 4;
int Zombie = 5;
int player1 = 0;
int player2 = 0;
String answer;
Scanner scan = new Scanner(System.in);
System.out.print("Hey, let's play Moropinzee!\n" +
"Please enter a move.\n");
do{
System.out.println("Player 1: Enter a number 1-5 for Monkey, Robot, Pirate, Ninja, or Zombie:");
while(!(player1>0) || !(player1<6))
{
player1 = scan.nextInt();
if(player1>=6)
System.out.println("Invalid choice, Player 1. Enter a number 1-5:");
}
Scanner keyboard = new Scanner(System.in);
System.out.println("Player 2: Enter a number 1-5 for Monkey, Robot, Pirate, Ninja, or Zombie:");
while(!(player2>0) || !(player2<6))
{
player2 = scan.nextInt();
if(player2>=6)
System.out.println("Invalid choice, Player 2. Enter a number 1-5:");
}
if(player1==(player2)){
System.out.println("Nobody wins!");
}
else if (player1==(1)){
if (player2==(4)){
System.out.println("Monkey fools Ninja! Player 1 Wins!");
}
}
else if (player2==(1)){
if (player1==(4)){
System.out.println("Monkey fools Ninja! Player 2 Wins! ");
}
}
if (player1==(1)){
if (player2==(2))
System.out.println("Monkey unplugs Robot! Player 1 Wins!");
}
if (player2==(1)){
if (player1==(2))
System.out.println("Monkey unplugs Robot! Player 2 Wins!");
}
if (player1==(2)){
if (player2==(4))
System.out.println("Robot chokes Ninja! Player 1 Wins!");
}
if (player1==(4)){
if (player2==(2))
System.out.println("Robot chokes Ninja! Player 2 Wins!");
}
if (player1==(2)){
if (player2==(5))
System.out.println("Robot crushes Zombie! Player 1 Wins!");
}
if (player1==(5)){
if (player2==(2))
System.out.println("Robot crushes Zombie! Player 2 Wins!");
}
if (player1==(3)){
if (player2==(2))
System.out.println("Pirate drowns Robot! Player 1 Wins!");
}
if (player1==(2)){
if (player2==(3))
System.out.println("Pirate drowns Robot! Player 2 Wins!");
}
if (player1==(3)){
if (player2==(1))
System.out.println("Pirate skewers Monkey! Player 1 Wins!");
}
if (player1==(1)){
if (player2==(3))
System.out.println("Pirate skewers Monkey! Player 2 Wins!");
}
if (player1==(4)){
if (player2==(3))
System.out.println("Ninja karate chops Pirate! Player 1 Wins!");
}
if (player1==(3)){
if (player2==(4))
System.out.println("Ninja karate chops Pirate! Player 2 Wins!");
}
if (player1==(4)){
if (player2==(5))
System.out.println("Ninja decapitates Zombie! Player 1 Wins!");
}
if (player1==(5)){
if (player2==(4))
System.out.println("Ninja decapitates Zombie! Player 2 Wins!");
}
if (player1==(5)){
if (player2==(3))
System.out.println("Zombie eats Pirate! Player 1 Wins!");
}
if (player1==(3)){
if (player2==(5))
System.out.println("Zombie eats Pirate! Player 2 Wins!");
}
if (player1==(5)){
if (player2==(1))
System.out.println("Zombie savages Monkey! Player 1 Wins!");
}
if (player1==(1)){
if (player2==(5))
System.out.println("Zombie savages Monkey! Player 2 Wins!");
}
System.out.println("Do you want to play again? Yes or No");
answer = keyboard.next();
}
while(answer.equalsIgnoreCase("Yes"));
}
}
https://i.stack.imgur.com/64H22.png