Java GUI受到长期处理的阻碍

时间:2014-04-03 19:59:40

标签: java multithreading user-interface freeze

我在java中编写一个鲍鱼游戏,我的AI会在每次移动时冻结UI 2-3秒。

public GameState doMove(Move move) {
    Color current = this.game.getTurn();
    if (current == Color.NONE) {
        return GameState.OUTOFTURNS;
    } else if (this.game.over()) {
        System.out.println("Partie terminé");
        return GameState.WON;
    }

    System.out.println("Application du mouvement de " + current);
    this.game.getBoard().apply(move);

    AI ai = AI.getInstance();

    System.out.println("On passe au tour suivant");
    Color next = this.game.getNextTurn();

    System.out.println("On met à jour la board");
    this.window.updateBoard(this.game.getTurn());

    if (next.equals(ai.getColor())) {
        System.out.print("L'IA joue... c'est long...");
        doMove(ai.getBestMove(next));
        System.out.println("fini");
    }

    return GameState.RUNNING;
}

我应该使用什么?线程,SwinWorker,可调用? 这是完整的源代码: https://github.com/melkir/Abalone/blob/master/src/main/java/com/github/abalone/controller/GameController.java

0 个答案:

没有答案