gpt4 book ai didi

java - 弹珠程序未删除

转载 作者:行者123 更新时间:2023-11-29 09:10:13 25 4
gpt4 key购买 nike

我在玩一个程序时遇到了一些问题。我正在尝试做这个弹珠游戏,玩家在其中与计算机对战并移除弹珠直到棋盘为空。我的问题是我用来移除弹珠的类(class)似乎并没有移除它。我认为这很简单,但我就是看不到。我认为遇到问题的部分是大写字母:

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);

其余不需要回答

最佳答案

条件 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();

关于java - 弹珠程序未删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12876563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com