Command refactor

This commit is contained in:
2025-04-13 12:29:47 +02:00
parent 9f44548843
commit a23c334994
11 changed files with 207 additions and 100 deletions

View File

@@ -34,7 +34,6 @@ public class CommandExecutor {
if (command instanceof PlayerCommand playerCommand && result != CommandResult.NotAllowed)
this.game.addAction(playerCommand);
command.postExec(game, dispatcher);
return result;
}
@@ -45,21 +44,23 @@ public class CommandExecutor {
return;
case ActionNeeded:
this.dispatcher.updateDisplay();
this.dispatcher.onBoardUpdate();
return;
case Moved:
if (checkGameStatus())
this.dispatcher.onBoardUpdate();
if (checkGameStatus()) {
this.dispatcher.onGameEnd();
return;
}
switchPlayerTurn();
this.dispatcher.updateDisplay();
return;
}
}
private void switchPlayerTurn() {
this.game.switchPlayerTurn();
this.dispatcher.playerTurn(this.game.getPlayerTurn());
this.dispatcher.onPlayerTurn(this.game.getPlayerTurn());
}
/**
@@ -71,19 +72,19 @@ public class CommandExecutor {
switch (gameStatus) {
case Check:
this.dispatcher.kingIsInCheck();
this.dispatcher.onKingInCheck();
return false;
case CheckMate:
this.dispatcher.kingIsInMat();
this.dispatcher.winnerIs(this.game.getPlayerTurn());
this.dispatcher.onKingInMat();
this.dispatcher.onWin(this.game.getPlayerTurn());
return true;
case OnGoing:
return false;
case Pat:
this.dispatcher.patSituation();
this.dispatcher.onPatSituation();
return true;
}