promote gui
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user