-2
我使用骰子卷创建了一个有趣的游戏GUI。代码看起来像这样:在Java中递归地调用游戏类
public class run {
//set up frame
Game game = new Game();
game.run();
}
public class Game {
public void run() {
Round round = new Round();
int playerWhoLostADie = round.run();
//handle if the game ends
//otherwise, call recursively
run(playerWhoLostADie);
}
}
public class Round {
public int run() {
Turn turn = new Turn();
Bet bet = turn.run();
//if the round is over
return(currentPlayer);
//otherwise, call recursively
run(bet);
}
}
public class Turn {
public Bet run() {
//handle betting
return bet;
}
}
是否正在调用轮次并递归地以一种智能方式执行此操作?我应该使用单独的线程以避免冻结GUI,如果是这样,怎么办?
不,不管你做什么,**不** **使用任何这种递归。而且可能不需要直接使用线程。只需使用一个摆动计时器。 –
我熟悉使用计时器进行延迟任务。你会如何推荐在这种情况下使用它们? –
我看不出有什么方法可以给你提供的具体建议,只有一般性的建议,因为我已经给了。如果你想要一个更具体的答案,你需要提高发布的信息的质量,包括给我们一个更好的想法你的程序结构和更有用的代码 - 准确地说[mcve]。 –