[英]Do-While loop doesn't seem to be working
因此,无论playerWins是否返回true或false,do while循环都会继续。 我试图做到这一点,以便如果玩家获胜,则游戏结束。 我无法弄清楚我的一生到底有什么问题。 我非常感谢所有帮助/提示。 谢谢!
int credibility = INITIAL_CREDIBILITY_LEVEL;
displayIntro();
userName = IR4.getString("\n" + "What are you called in your city?");
for(counter = 1; counter <= NBR_OF_ROUNDS; counter ++)
{
do
{
if(counter == 1)
{
displayFirstRoundHeader(userName);
}
else
{
displayRoundHeader();
}
combination = IR4.getRandomNumber(STARTING_LOW, STARTING_HIGH);
System.err.println(combination);
playerWins = playRound(combination);
credibility -= CREDIBILITY_LOST;
if(playerWins)
System.out.println("Yay you win");
else if(credibility == 0)
{
displayRoundLossText(userName, credibility, combination);
displayLossText(userName);
}
else
displayRoundLossText(userName, credibility, combination);
}
while(!playerWins);
玩家获胜时,您必须退出外部for循环。 将计数器设置为使您的for循环条件为假的值
if(playerWins)
{
System.out.println("Yay you win");
counter = NBR_OF_ROUNDS + 1; //to break out of the outer most for loop
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.