check draw
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -42,4 +42,7 @@ public abstract class GameAdaptator implements GameListener {
|
||||
@Override
|
||||
public void onMoveNotAllowed(Move move) {}
|
||||
|
||||
@Override
|
||||
public void onDraw() {}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user