This commit is contained in:
2025-04-18 22:19:47 +02:00
parent 4a58136afe
commit dd6e033528
12 changed files with 89 additions and 47 deletions

View File

@@ -19,7 +19,7 @@ public class CommandExecutor {
public CommandExecutor(Game game) {
this(game, new GameDispatcher());
}
public CommandExecutor(Game game, GameDispatcher dispatcher) {
this.game = game;
this.dispatcher = dispatcher;
@@ -52,18 +52,21 @@ public class CommandExecutor {
return;
case Moved:
boolean notifyPlayerTurn = true;
this.dispatcher.onBoardUpdate();
if (checkGameStatus()) {
this.dispatcher.onGameEnd();
notifyPlayerTurn = false;
}
switchPlayerTurn(command instanceof UndoCommand);
switchPlayerTurn(command instanceof UndoCommand, notifyPlayerTurn);
return;
}
}
private void switchPlayerTurn(boolean undone) {
private void switchPlayerTurn(boolean undone, boolean notifyPlayerTurn) {
this.game.switchPlayerTurn();
this.dispatcher.onPlayerTurn(this.game.getPlayerTurn(), undone);
if (notifyPlayerTurn)
this.dispatcher.onPlayerTurn(this.game.getPlayerTurn(), undone);
}
/**