可爱的人, 我坚持使用我的java程序。如果我运行我的程序它不起作用它应该如何工作。如果computerSpeler抛出1或2x 1,则轮到他应该是mensSpeler。我的计划有什么问题?
import java.util.Random;
public class Spel {
private EgbertComputerSpeler computerSpeler;
private MensSpeler mensSpeler;
private boolean mensSpelerBegint;
public static final int HET_SPEL_IS_UIT_SCORE = 100;
private int dobbelsteen1;
private int dobbelsteen2;
private Random generator = new Random();
private int scoreComputer;
private int scoreMens;
private int worpen;
private int beurt;
public Spel() {
computerSpeler = new EgbertComputerSpeler(HET_SPEL_IS_UIT_SCORE);
mensSpeler = new MensSpeler(HET_SPEL_IS_UIT_SCORE);
mensSpelerBegint = generator.nextBoolean();
}
public void dobbel() {
dobbelsteen1 = generator.nextInt(6) + 1;
dobbelsteen2 = generator.nextInt(6) + 1;
worpen = worpen + 1;
beurt = beurt + dobbelsteen1 + dobbelsteen2;
}
public void speelSpel() {
while (scoreMens <100 || scoreComputer < 100) {
if (mensSpelerBegint) {
do {
dobbel();
if (dobbelsteen1 == 1 && dobbelsteen2 == 1) {
scoreMens = scoreMens + 25 ;
mensSpelerBegint = false;
}
else if (dobbelsteen1 == 1 || dobbelsteen2 == 1) {
scoreMens = scoreMens + 0 ;
mensSpelerBegint = false;}
} while (mensSpeler.wilGooien(false, worpen,
scoreMens, scoreComputer));
scoreMens = beurt + scoreMens;
worpen = 0;
beurt = 0;
}
else {
do {
dobbel();
if (dobbelsteen1 == 1 && dobbelsteen2 == 1) {
scoreComputer = scoreComputer + 25;
mensSpelerBegint = true;}
else if (dobbelsteen1 == 1 || dobbelsteen2 == 1) {
scoreComputer = scoreComputer + 0;
mensSpelerBegint = true;}
} while (computerSpeler.wilGooien(false, worpen,
scoreMens, scoreComputer));
scoreComputer = beurt + scoreComputer;
worpen = 0;
beurt = 0;
}
}
}
}
谢谢!
答案 0 :(得分:1)
你的问题是代码基本上是这样的(假设我正确理解了代码)
if turn == player:
while player wants to continue:
if bad stuff:
turn = computer
else
....
endif
是的,您将其设置为计算机,但它仍然停留在do-while
循环中,直到wilGooien
设置为false。
除了将其设置为计算机之外,您需要做的是break;
离开循环。