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