我正在玩一个我正在玩的程序有些问题。我正在尝试做这个大理石游戏,玩家在电脑上玩游戏并移除弹珠,直到棋盘空了。我的问题是我用来移除弹珠的类似乎没有删除它。我认为这很简单,但我只是看不到它。我认为我遇到麻烦的部分是大写字母:
Pile tiles = new Pile();
tiles.createMarbles();
marbles = tiles.getMarbles();
System.out.println("There are now " + marbles + " left!");
HumanPlayer hum = new HumanPlayer();
SmartMode cpu = new SmartMode();
StupidMode badcpu = new StupidMode();
//ComputerMove cpu = new ComputerMove();
//PlayerMove hum = new PlayerMove();
do {
if (compMove == true && marbles > 1) {
if (compSmart) {
//marbles = cpu.move(marbles);
tiles.removesMarbles(cpu.move(marbles)); //THIS RIGHT HERE
System.out.println("There are now " + marbles + " left!");
compMove = false;
} if (!compSmart) {
//marbles = badcpu.move(marbles);
tiles.removesMarbles(badcpu.move(marbles)); // THIS RIGHT HERE
System.out.println("There are now " + marbles + " left!");
compMove = false;
}
/* marbles = (cpu.ComputerMove(marbles, compSmart));
System.out.println("There are now " + marbles + " left!");
compMove = false;*/
} else if (compMove == false && marbles > 1) {
//marbles = (hum.move(marbles));
tiles.removesMarbles(hum.move(marbles)); // THIS RIGHT HERE
System.out.println("There are now " + marbles + " left!");
compMove = true;
}
} while (marbles > 1);
答案不需要其余的
答案 0 :(得分:0)
条件while (marbles > 1)
不会更改,因为在循环中未分配marbles
。
使用:
while (tiles.getMarbles() > 1)
您使用构造:
do {
if (... && marbles > 1 ) {}
...
} while(marbles > 1)
可能会这样做:
while (tiles.getMarbles() > 0 ) {
// additional condition on marbles not required.
if (...) {}
}
interface Movable {
public int move();
}
class SmartPlayer implements Movable {
public int move() {...}
}
Movable m = new SmartPlayer();
m.move();