Command refactor
This commit is contained in:
@@ -188,29 +188,25 @@ public class Window extends JFrame implements GameListener {
|
||||
}
|
||||
if (!this.lastClick.equals(new Coordinate(x, y))) {
|
||||
Move move = new Move(lastClick, new Coordinate(x, y));
|
||||
|
||||
if (sendCommand(new MoveCommand(move)) == CommandResult.NotAllowed) {
|
||||
drawInvalid(move);
|
||||
}
|
||||
sendCommand(new MoveCommand(move));
|
||||
}
|
||||
this.lastClick = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerTurn(chess.model.Color color) {
|
||||
public void onPlayerTurn(chess.model.Color color) {
|
||||
this.displayText.setText("Current turn: " + color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void winnerIs(chess.model.Color color) {
|
||||
public void onWin(chess.model.Color color) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
JOptionPane.showMessageDialog(this, "Victory of " + color);
|
||||
onGameEnd();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kingIsInCheck() {
|
||||
public void onKingInCheck() {
|
||||
if (!showPopups)
|
||||
return;
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
@@ -219,39 +215,40 @@ public class Window extends JFrame implements GameListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kingIsInMat() {
|
||||
public void onKingInMat() {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
JOptionPane.showMessageDialog(this, "Checkmate!");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void patSituation() {
|
||||
public void onPatSituation() {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
JOptionPane.showMessageDialog(this, "Pat. It's a draw!");
|
||||
onGameEnd();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasSurrendered(chess.model.Color color) {
|
||||
public void onSurrender(chess.model.Color color) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
JOptionPane.showMessageDialog(this, color + " has surrendered.");
|
||||
});
|
||||
}
|
||||
|
||||
private void onGameEnd() {
|
||||
@Override
|
||||
public void onGameEnd() {
|
||||
JOptionPane.showMessageDialog(this, "End of the game");
|
||||
this.dispose();
|
||||
this.commandExecutor.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gameStarted() {
|
||||
public void onGameStart() {
|
||||
buildBoard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void promotePawn(Coordinate pieceCoords) {
|
||||
public void onPromotePawn(Coordinate pieceCoords) {
|
||||
if (!showPopups)
|
||||
return;
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
@@ -290,8 +287,16 @@ public class Window extends JFrame implements GameListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDisplay() {
|
||||
public void onBoardUpdate() {
|
||||
updateBoard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(Move move) {}
|
||||
|
||||
@Override
|
||||
public void onMoveNotAllowed(Move move) {
|
||||
drawInvalid(move);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user