猪游戏Java代码;你能帮助我吗?

猪游戏Java代码;你能帮助我吗?,java,while-loop,do-while,Java,While Loop,Do While,我花了很长时间才注意到(totalScores2>=100)最后有“;”。删除它,否则if语句毫无意义正如我前面所说的,您必须删除该语句末尾的分号: Welcome to the game of Pig! You rolled: 4 Your turn score is 4 and your total scores is 0 If you hold, you will have 4 points. Enter 'r' to roll again, 'h' to hold. h Your sc

我花了很长时间才注意到(totalScores2>=100)最后有“;”。删除它,否则if语句毫无意义

正如我前面所说的,您必须删除该语句末尾的分号:

Welcome to the game of Pig!

You rolled: 4
Your turn score is 4 and your total scores is 0
If you hold, you will have 4 points.
Enter 'r' to roll again, 'h' to hold.
h
Your score is 4

It is the computer's turn.
The computer rolled: 6
The computer rolled: 4
The computer rolled: 2
The computer rolled: 5
The computer rolled: 5
The computer holds
The computer's scores is 22

THE COMPUTER WINS!
如果未删除该语句,则If语句将被视为关闭语句,跳过,执行print语句,然后执行
break
。在该阶段,您处于整个
循环中,而
循环中,break将简单地退出系统

然而,即使修复了它,也不会使游戏功能完全正确。这是因为只有当掷骰子=1时,才重置
得分。这是不对的

如果我的回合得分为20,并选择保持,则需要将其重置为0,否则当我开始下一次围棋时,我就已经有20分了

解决方案是在回合结束时的分数打印语句之后重置回合分数,如下所示:

if(totalScores2 >= 100);
然后对于计算机:

totalScores += turnScores;
System.out.println("Your scroes is " + totalScores);
turnScores = 0;

首先,Javascript不是Java-请从您的问题中删除该标记。您的最终if语句(if(totalScores2>=100)被关闭,因为后面有一个分号。删除它。我将问题回滚。如果有人帮助您,请接受他们的答案;不要破坏原始问题。
totalScores += turnScores;
System.out.println("Your scroes is " + totalScores);
turnScores = 0;
totalScores2 += turnScores2;
System.out.println("The computer's scores is " + totalScores2 + "\n");
turnScores2 = 0;