Fixed checkmate detection, simplified event handling
This commit is contained in:
@ -8,13 +8,10 @@ import java.awt.event.ComponentEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import dev.kske.chess.board.Board;
|
||||
import dev.kske.chess.board.Move;
|
||||
import dev.kske.chess.event.GameEvent;
|
||||
import dev.kske.chess.event.GameEventListener;
|
||||
|
||||
/**
|
||||
* Project: <strong>Chess</strong><br>
|
||||
@ -26,7 +23,7 @@ import dev.kske.chess.event.GameEventListener;
|
||||
* this must be added to a parent component that allows the child to decide the
|
||||
* size.
|
||||
*/
|
||||
public class BoardPanel extends JPanel implements GameEventListener {
|
||||
public class BoardPanel extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 6771148331334310216L;
|
||||
|
||||
@ -90,18 +87,6 @@ public class BoardPanel extends JPanel implements GameEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGameEvent(GameEvent evt) {
|
||||
switch (evt.getEventType()) {
|
||||
case CHECK:
|
||||
JOptionPane.showMessageDialog(this, evt.getColor().toString() + " in check!");
|
||||
break;
|
||||
case CHECKMATE:
|
||||
JOptionPane.showMessageDialog(this, evt.getColor().toString() + " in checkmate!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays move destinations on the board.
|
||||
*
|
||||
@ -142,10 +127,5 @@ public class BoardPanel extends JPanel implements GameEventListener {
|
||||
|
||||
public Board getBoard() { return board; }
|
||||
|
||||
public void setBoard(Board board) {
|
||||
this.board = board;
|
||||
|
||||
// Register this BoardPanel as a GameEventListener to the board
|
||||
board.registerGameEventListener(this);
|
||||
}
|
||||
public void setBoard(Board board) { this.board = board; }
|
||||
}
|
||||
|
@ -49,8 +49,7 @@ public class GameModeDialog extends JDialog {
|
||||
Map<Color, Player> players = new HashMap<>();
|
||||
players.put(Color.WHITE, new NaturalPlayer(boardPanel.getBoard(), Color.WHITE, boardPanel));
|
||||
players.put(Color.BLACK, new AIPlayer(boardPanel.getBoard(), Color.BLACK));
|
||||
new Game(players, boardPanel.getBoard(), boardPanel).start();
|
||||
dispose();
|
||||
startGame(players, boardPanel);
|
||||
});
|
||||
getContentPane().add(btnAI);
|
||||
|
||||
@ -59,9 +58,13 @@ public class GameModeDialog extends JDialog {
|
||||
Map<Color, Player> players = new HashMap<>();
|
||||
players.put(Color.WHITE, new AIPlayer(boardPanel.getBoard(), Color.WHITE));
|
||||
players.put(Color.BLACK, new AIPlayer(boardPanel.getBoard(), Color.BLACK));
|
||||
new Game(players, boardPanel.getBoard(), boardPanel).start();
|
||||
dispose();
|
||||
startGame(players, boardPanel);
|
||||
});
|
||||
getContentPane().add(btnAI2);
|
||||
}
|
||||
|
||||
private void startGame(Map<Color, Player> players, BoardPanel boardPanel) {
|
||||
new Game(players, boardPanel.getBoard(), boardPanel).start();
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user