add CommandResult.NeedsAction

This commit is contained in:
2025-04-04 20:55:46 +02:00
parent 416cfadc9b
commit 7b07423175
5 changed files with 43 additions and 20 deletions

View File

@@ -1,7 +1,6 @@
package chess.io;
import chess.io.Command.CommandResult;
import chess.io.commands.MoveCommand;
import chess.model.Game;
import chess.model.Game.GameStatus;
@@ -29,21 +28,21 @@ public class CommandExecutor {
}
private void processResult(Command command, CommandResult result) {
if (result != CommandResult.Moved)
return;
if (command instanceof MoveCommand move) {
boolean needsPromote = this.game.pawnShouldBePromoted();
if (needsPromote)
this.outputSystem.promotePawn(move.getMove().getFinish());
if (checkGameStatus())
switch (result) {
case NotAllowed:
case NotMoved:
return;
if(!needsPromote)
case ActionNeeded:
this.outputSystem.updateDisplay();
return;
case Moved:
if (checkGameStatus())
return;
switchPlayerTurn();
} else if (command instanceof PlayerCommand) {
switchPlayerTurn();
this.outputSystem.updateDisplay();
return;
}
}
@@ -63,7 +62,7 @@ public class CommandExecutor {
case Check:
this.outputSystem.kingIsInCheck();
return false;
case CheckMate:
this.outputSystem.kingIsInMat();
this.outputSystem.winnerIs(this.game.getPlayerTurn());