post exec
This commit is contained in:
@@ -16,4 +16,6 @@ public abstract class Command {
|
||||
}
|
||||
|
||||
public abstract CommandResult execute(Game game, OutputSystem outputSystem);
|
||||
|
||||
public void postExec(Game game, OutputSystem outputSystem) {}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public class CommandExecutor {
|
||||
assert result != CommandResult.Moved || command instanceof PlayerCommand;
|
||||
|
||||
processResult(command, result);
|
||||
command.postExec(game, outputSystem);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class MoveCommand extends PlayerCommand {
|
||||
return CommandResult.NotAllowed;
|
||||
}
|
||||
|
||||
if (shouldPromote(game, outputSystem))
|
||||
if (game.pawnShouldBePromoted())
|
||||
return CommandResult.ActionNeeded;
|
||||
|
||||
return CommandResult.Moved;
|
||||
@@ -63,14 +63,18 @@ public class MoveCommand extends PlayerCommand {
|
||||
board.undoMove(move, deadPiece);
|
||||
}
|
||||
|
||||
private boolean shouldPromote(Game game, OutputSystem outputSystem) {
|
||||
@Override
|
||||
public void postExec(Game game, OutputSystem outputSystem) {
|
||||
tryPromote(game, outputSystem);
|
||||
}
|
||||
|
||||
private void tryPromote(Game game, OutputSystem outputSystem) {
|
||||
Coordinate pawnPos = game.pawnPromotePosition();
|
||||
|
||||
if (pawnPos == null)
|
||||
return false;
|
||||
return;
|
||||
|
||||
outputSystem.promotePawn(pawnPos);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user