check draw

This commit is contained in:
2025-04-13 12:57:13 +02:00
parent 224a09c711
commit b336784a5d
15 changed files with 108 additions and 26 deletions

View File

@@ -59,7 +59,11 @@ public class CommandExecutor {
}
private void switchPlayerTurn() {
this.game.switchPlayerTurn();
if(this.game.switchPlayerTurn()) {
this.dispatcher.onDraw();
this.dispatcher.onGameEnd();
return;
}
this.dispatcher.onPlayerTurn(this.game.getPlayerTurn());
}

View File

@@ -42,4 +42,7 @@ public abstract class GameAdaptator implements GameListener {
@Override
public void onMoveNotAllowed(Move move) {}
@Override
public void onDraw() {}
}

View File

@@ -10,7 +10,7 @@ import chess.model.Color;
import chess.model.Coordinate;
import chess.model.Move;
public class GameDispatcher implements GameListener{
public class GameDispatcher implements GameListener {
private final List<GameListener> listeners;
private final ExecutorService executor;
@@ -88,6 +88,11 @@ public class GameDispatcher implements GameListener{
asyncForEachCall((l) -> l.onMoveNotAllowed(move));
}
@Override
public void onDraw() {
asyncForEachCall((l) -> l.onDraw());
}
public void stopService() {
this.executor.shutdown();
}

View File

@@ -10,6 +10,11 @@ public interface GameListener {
* Invoked when the display of the board should be updated
*/
void onBoardUpdate();
/**
* Invoked when a draw occurs (same position is repeated three times)
*/
void onDraw();
/**
* Invoked when the game has ended (by a win or a draw)