0

ロールが 1 でない場合、ロールを「保留」したいと思います。コードは、"h" ブラケット条件ステートメント内の命令を無視し、もう一度サイコロを振ります。1 をロールすると、コードが機能してコンピューターのターンに進み、フラグが正しく設定されるため、混乱しています。

while ((humanScore <= 100) && (computerScore <=100))
    {
        /*loop while human turn is true*/
        while ((humanTurn == true) && (computerTurn == false))
        {
            die = randomGenerator.nextInt(6) + 1;

            if(die == 1)
            {
                System.out.println("Human, you rolled a 1, you lose your points and your turn.");
                humanTurn = false;
                computerTurn = true;
                points = 0;
                System.out.println("Your score is now " + humanScore);
                System.out.println("Computer, it is now your turn.");
            }

            else if(die != 1)
            {
                System.out.println("Human, you currently have " + points + " points to add to score.");
                System.out.println("You have rolled a " + die + " would you like to hold, or roll again?");
                System.out.println("Please enter either r to roll, or h to hold.");
                points = points + die;
                decision = scanner.next();

                if (decision == "r")
                {
                    humanTurn = true;
                }

                if(decision == "h")
                {
                    humanScore = humanScore + points;
                    humanTurn = false;
                    computerTurn = true;
                    points = 0;
                    System.out.println("You hold, your score is now " + humanScore);
                    System.out.println("Computer, it is now your turn.");
                }

            }
        }
4

1 に答える 1