promote gui

This commit is contained in:
2025-04-03 22:06:34 +02:00
parent 927ba129f6
commit 0d72e015f1
5 changed files with 91 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
package chess.io;
import chess.io.commands.MoveCommand;
import chess.io.commands.PromoteCommand;
import chess.model.Game;
public class CommandExecutor {
@@ -18,12 +19,24 @@ public class CommandExecutor {
assert this.outputSystem != null : "No output system specified !";
CommandResult result = command.execute(this.game, this.outputSystem);
if (result == CommandResult.Moved) {
this.game.checkPromotion(((MoveCommand) command).getMove().getFinish());
this.game.checkGameStatus();
processResult(command, result);
return result;
}
private void processResult(Command command, CommandResult result) {
if (result != CommandResult.Moved)
return;
if (command instanceof MoveCommand move) {
boolean needsPromote = this.game.checkPromotion(move.getMove().getFinish());
if (this.game.checkGameStatus())
return;
if (!needsPromote)
this.game.switchPlayerTurn();
} else if (command instanceof PromoteCommand) {
this.game.switchPlayerTurn();
}
return result;
}
public void setOutputSystem(OutputSystem outputSystem) {
@@ -60,6 +73,4 @@ public class CommandExecutor {
this.game.OnPlayerTurn.connect(outputSystem::playerTurn);
}
}