Java 双人猪游戏问题

Java 双人猪游戏问题,java,Java,因此,我在计算机科学2课程中的任务是制作一个两人玩的猪游戏。我相信我已经解决了大部分问题,但出于某种原因,我得到了某种语义错误。播放器1的代码运行得很好,但是当涉及到播放器2时,即使我告诉它返回到播放器1,它也不会退出。如果你能给我指出正确的方向,我将不胜感激 public static void main(String[] args) { int player1TurnScore = 0; int player1TotalScore = 0; int player2Tu

因此,我在计算机科学2课程中的任务是制作一个两人玩的猪游戏。我相信我已经解决了大部分问题,但出于某种原因,我得到了某种语义错误。播放器1的代码运行得很好,但是当涉及到播放器2时,即使我告诉它返回到播放器1,它也不会退出。如果你能给我指出正确的方向,我将不胜感激

public static void main(String[] args) {
    int player1TurnScore = 0;
    int player1TotalScore = 0;
    int player2TurnScore = 0;
    int player2TotalScore = 0;
    int dice;
    int dice2;
    String input = "r";
    char repeat;

    Scanner keyboard = new Scanner(System.in);
    Random diceRoll = new Random();

    System.out.println("Welcome to the game of Pig!\n");

    while(player1TotalScore < 100 || player2TotalScore < 100){
        // human's turn
        do{
            dice = diceRoll.nextInt(6) + 1;
            System.out.println("You rolled a " + dice);

            if(dice == 1){
                player1TurnScore = 0;
                System.out.println("You lose your turn!");
                System.out.println("Your total score is " + player1TotalScore);
                break;
            }else{
                player1TurnScore += dice;
                System.out.println("Your turn score is " + player1TurnScore);
                System.out.println("And your total score is " + player1TotalScore);
                System.out.println("If you hold, " + player1TurnScore + " points will be added to your total score.");
                System.out.println("Enter 'r' to roll again, or 'h' to hold.");
                input = keyboard.nextLine();
                repeat = input.charAt(0);

                if(repeat == 'h'){
                    break;
                }
            }
        }while(input.equalsIgnoreCase("r") || dice != 1);

        player1TotalScore += player1TurnScore;
        System.out.println("Your score is " + player1TotalScore);
        player1TurnScore = 0;

        if(player1TotalScore >= 100){
            System.out.println("Your total score is " + player1TotalScore);
            System.out.println("PLAYER 1 WINS!");
            break;
        }

        // Player 2's turn
        System.out.println();
        System.out.println("It is Player 2's turn.");
        do{
            dice2 = diceRoll.nextInt(6) + 1;
            System.out.println("You rolled a " + dice2);

            if(dice2 == 1){
                player2TurnScore = 0;
                System.out.println("You lose your turn!");
                System.out.println("Your total score is " + player2TotalScore);
                break;
            }else{
                player2TurnScore += dice2;
                System.out.println("Your turn score is " + player2TurnScore);
                System.out.println("And your total score is " + player2TotalScore);
                System.out.println("If you hold, " + player2TurnScore + " points will be added to your total score.");
                System.out.println("Enter 'r' to roll again, or 'h' to hold.");
                input = keyboard.nextLine();
                repeat = input.charAt(0);

                if(repeat == 'h'){
                    break;
                }
            }
        }while(input.equalsIgnoreCase("r") || dice2 != 1);

        player2TotalScore += player2TurnScore;
        System.out.println("Your score is " + player2TotalScore);
        player2TurnScore = 0;

        if(player2TotalScore >= 100){
            System.out.println("Your total score is " + player2TotalScore);
            System.out.println("PLAYER 2 WINS!");
            break;
        }
    }
我希望我做的缩进正确,因为这是我的第一篇文章。如果有问题,请告诉我

替换:

}while(input.equalsIgnoreCase("r") || dice != 1);
仅仅

} while(dice != 1);

您得到的确切错误是什么?对于Eclipse中的缩进,CTRL+A CTRL+I