fix moves preview

This commit is contained in:
2025-04-10 11:07:44 +02:00
parent 19b45371bb
commit 7aa129bbc6
2 changed files with 3 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
package chess.controller; package chess.controller;
import chess.controller.Command.CommandResult; import chess.controller.Command.CommandResult;
import chess.controller.commands.UndoCommand;
import chess.model.Game; import chess.model.Game;
import chess.model.Game.GameStatus; import chess.model.Game.GameStatus;
@@ -21,7 +22,7 @@ public class CommandExecutor {
CommandResult result = command.execute(this.game, this.outputSystem); CommandResult result = command.execute(this.game, this.outputSystem);
// non player commands are not supposed to return move result // non player commands are not supposed to return move result
assert result != CommandResult.Moved || command instanceof PlayerCommand; assert result != CommandResult.Moved || command instanceof PlayerCommand || command instanceof UndoCommand;
processResult(command, result); processResult(command, result);

View File

@@ -138,19 +138,7 @@ public class Window extends JFrame implements OutputSystem {
} }
} }
private void clearPreviews() {
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
JLabel cell = this.cells[x][y];
cell.paintComponents(getGraphics());
}
}
}
private boolean previewMoves(int x, int y) { private boolean previewMoves(int x, int y) {
clearPreviews();
GetAllowedMovesCommand movesCommand = new GetAllowedMovesCommand(new Coordinate(x, y)); GetAllowedMovesCommand movesCommand = new GetAllowedMovesCommand(new Coordinate(x, y));
if (sendCommand(movesCommand) == CommandResult.NotAllowed) if (sendCommand(movesCommand) == CommandResult.NotAllowed)
return false; return false;
@@ -180,13 +168,13 @@ public class Window extends JFrame implements OutputSystem {
for (int x = 0; x < 8; x++) { for (int x = 0; x < 8; x++) {
JLabel cell = this.cells[x][y]; JLabel cell = this.cells[x][y];
cell.setBackground(getCellColor(x, y)); cell.setBackground(getCellColor(x, y));
cell.paint(cell.getGraphics());
} }
} }
} }
private void onCellClicked(int x, int y) { private void onCellClicked(int x, int y) {
clearMoves(); clearMoves();
clearPreviews();
if (this.lastClick == null) { if (this.lastClick == null) {
if (isCellEmpty(x, y)) if (isCellEmpty(x, y))
return; return;