[英]While-loop freezing
I'm currently making a paper-rock-scissors game where you play against the computer. 我目前正在制作纸剪刀布游戏,您可以在电脑上玩。 My while-loop for controlling who's reached the maximum score keeps freezing.
我控制住谁达到最高分的while循环一直保持冻结。 I hope the method below isn't too hard to read and has sufficient information.
我希望下面的方法不会太难阅读并且有足够的信息。 Basically when I play the game and try to make a move the program just freezes.
基本上,当我玩游戏并尝试移动时,程序会冻结。 I've tried the program without the while-loop and it works fine.
我已经尝试了不使用while循环的程序,但是效果很好。 I made it so every move is a number.
我做到了,所以每一步都是一个数字。 0 for rock, 1 for scissor and 2 for paper.
0代表岩石,1代表剪刀,2代表纸张。 The method computerPlayer.newChoice();
方法computerPlayer.newChoice(); is a random-generated number from another class.
是另一类的随机生成的数字。
public void newChoice() {
while (humanS < 3 && computerS < 3) {
computerPlayer.newChoice();
if (playerChoice == 0) {
viewer.jLblHumanM.setText("Sten");
if (computerPlayer.choice == 0) {
viewer.jLblComputerM.setText("Sten");
} else if (computerPlayer.choice == 1) {
HScore += 1;
viewer.jLblComputerM.setText("Sax");
viewer.jLblHumanS.setText("" + HScore);
} else if (computerPlayer.choice == 2) {
CScore += 1;
viewer.jLblComputerM.setText("Påse");
viewer.jLblComputerS.setText("" + CScore);
}
} else if (playerChoice == 1) {
viewer.jLblHumanM.setText("Sax");
if (computerPlayer.choice == 0) {
HScore += 1;
viewer.jLblComputerM.setText("Sten");
viewer.jLblHumanS.setText("" + HScore);
} else if (computerPlayer.choice == 1) {
viewer.jLblComputerM.setText("Sax");
} else if (computerPlayer.choice == 2) {
HScore += 1;
viewer.jLblComputerM.setText("Påse");
viewer.jLblHumanS.setText("" + HScore);
}
} else if (playerChoice == 2) {
viewer.jLblHumanM.setText("Påse");
if (computerPlayer.choice == 0) {
viewer.jLblComputerM.setText("Sten");
HScore += 1;
viewer.jLblHumanS.setText("" + HScore);
} else if (computerPlayer.choice == 1) {
viewer.jLblComputerM.setText("Sax");
CScore += 1;
viewer.jLblComputerS.setText("" + CScore);
} else if (computerPlayer.choice == 2) {
viewer.jLblComputerM.setText("Påse");
}
}
}
}
You have too many variables. 您的变量太多。 humanS and HScore and compterS and CScore seem to be duplicative, as well as the source of your problem.
humanS和HScore以及compterS和CScore似乎是重复的,也是问题的根源。
while(humanS < 3 && computerS < 3){
This should be 这应该是
while(HScore < 3 && CScore < 3){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.