This commit is contained in:
@@ -62,6 +62,10 @@ public class Window extends JFrame implements GameListener, CommandSender {
|
||||
return ((x + y) % 2 == 1) ? Color.DARK_GRAY : Color.LIGHT_GRAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and set the buttons of the window.
|
||||
* @param bottom the Jpanel in which to add the buttons
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private void buildButtons(JPanel bottom) {
|
||||
castlingButton.addActionListener((event) -> {
|
||||
@@ -81,6 +85,9 @@ public class Window extends JFrame implements GameListener, CommandSender {
|
||||
bottom.add(undoButton);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the playable board in the window.
|
||||
*/
|
||||
private void buildBoard() {
|
||||
JPanel content = new JPanel();
|
||||
JPanel grid = new JPanel(new GridLayout(8, 8));
|
||||
@@ -117,6 +124,9 @@ public class Window extends JFrame implements GameListener, CommandSender {
|
||||
updateBoard();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the board with the newest pieces' positions.
|
||||
*/
|
||||
private void updateBoard() {
|
||||
PieceIcon pieceIcon = new PieceIcon();
|
||||
for (int y = 0; y < 8; y++) {
|
||||
@@ -131,6 +141,12 @@ public class Window extends JFrame implements GameListener, CommandSender {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the possible moves of the piece at the given coordinates
|
||||
* @param x position of the piece on the x axis
|
||||
* @param y position of the piece on the y axis
|
||||
* @return true if the piece has possible moves, false otherwise
|
||||
*/
|
||||
private boolean previewMoves(int x, int y) {
|
||||
List<Coordinate> allowedMoves = getPieceAllowedMoves(new Coordinate(x, y));
|
||||
if (allowedMoves.isEmpty())
|
||||
@@ -162,6 +178,11 @@ public class Window extends JFrame implements GameListener, CommandSender {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the click on a cell. Cancel previous rendering, move the previously selected piece if needed.
|
||||
* @param x position of the cell on the x axis
|
||||
* @param y position of the cell on the y axis
|
||||
*/
|
||||
private void onCellClicked(int x, int y) {
|
||||
clearMoves();
|
||||
if (this.lastClick == null) {
|
||||
@@ -233,6 +254,9 @@ public class Window extends JFrame implements GameListener, CommandSender {
|
||||
buildBoard();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a dialog box when a pawn needs to be promoted
|
||||
*/
|
||||
@Override
|
||||
public void onPromotePawn(Coordinate pieceCoords) {
|
||||
if (!showPopups)
|
||||
|
||||
Reference in New Issue
Block a user