我的问题与一般游戏算法无关。当我对“你想继续吗?输入真或假。”这个问题回答“真”时,程序输出:
"Player one, throw your shape(rock, paper, scissors)!
Player two, throw your shape(rock, paper, scissors)!"
所以我可以在第一个周期输入值,但不能在第二个周期输入。我该如何解决?谢谢。
代码:
public static void main(String[] args) {
String playerOne;
String playerTwo;
Scanner myScan = new Scanner(System.in);
boolean playAgain = true;
do
{
System.out.println("Player one, throw your shape(rock, paper, scissors)! ");
playerOne = myScan.nextLine();
System.out.println("Player two, throw your shape(rock, paper, scissors)! ");
playerTwo = myScan.nextLine();
if (playerOne.equals("scissors") && playerTwo.equals("rock"))
{
System.out.println("Player one lost! Playr two won!");
}
else if (playerOne.equals("scissors") && playerTwo.equals("paper"))
{
System.out.println("Player one won! Player two lost!");
}
else if (playerOne.equals("rock") && playerTwo.equals("paper"))
{
System.out.println("Player one lost! Player two won!");
}
else if (playerOne.equals("rock") && playerTwo.equals("scissors"))
{
System.out.println("Player one won! Player two lost!");
}
else if (playerOne.equals("paper") && playerTwo.equals("scissors"))
{
System.out.println("Player one lost! Player two won!");
}
else if (playerOne.equals("paper") && playerTwo.equals("rock"))
{
System.out.println("Player one won! Player two lost!");
}
System.out.println("Do you want to continue? Enter true or false.");
playAgain = myScan.nextBoolean();
}while(playAgain);
}
}