如果我没有掷出 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.");
}
}
}