feat: add app chooser
All checks were successful
Linux arm64 / Build (push) Successful in 43s

This commit is contained in:
2025-05-26 21:33:02 +02:00
parent 9d65432eff
commit 86ea62614b
11 changed files with 319 additions and 62 deletions

View File

@@ -23,34 +23,36 @@ import chess.controller.commands.PromoteCommand.PromoteType;
import chess.controller.event.GameListener;
import chess.model.Coordinate;
import chess.model.Move;
import chess.model.Piece;
import chess.view.GameView;
/**
* Window for the 2D chess game.
*/
public class Window extends JFrame implements GameListener, CommandSender {
public class Window extends GameView {
private final CommandExecutor commandExecutor;
private Coordinate lastClick = null;
private final JFrame frame;
private final JLabel cells[][];
private final JLabel displayText;
private final JButton castlingButton = new JButton("Roque");
private final JButton bigCastlingButton = new JButton("Grand Roque");
private final JButton undoButton = new JButton("Annuler le coup précédent");
private final boolean showPopups;
public Window(final CommandExecutor commandExecutor, boolean showPopups) {
public Window(final CommandExecutor commandExecutor) {
this.frame = new JFrame();
this.cells = new JLabel[8][8];
this.displayText = new JLabel();
this.commandExecutor = commandExecutor;
this.showPopups = showPopups;
setSize(800, 910);
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
this.frame.setSize(800, 910);
this.frame.setVisible(true);
this.frame.setLocationRelativeTo(null);
this.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
commandExecutor.close();
@@ -99,7 +101,7 @@ public class Window extends JFrame implements GameListener, CommandSender {
content.add(grid);
content.add(bottom);
setContentPane(content);
this.frame.setContentPane(content);
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
@@ -213,39 +215,37 @@ public class Window extends JFrame implements GameListener, CommandSender {
@Override
public void onWin(chess.model.Color color) {
JOptionPane.showMessageDialog(this, "Victory of " + color);
JOptionPane.showMessageDialog(this.frame, "Victory of " + color);
}
@Override
public void onKingInCheck() {
if (!showPopups)
return;
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(this, "Check!");
JOptionPane.showMessageDialog(this.frame, "Check!");
});
}
@Override
public void onKingInMat() {
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(this, "Checkmate!");
JOptionPane.showMessageDialog(this.frame, "Checkmate!");
});
}
@Override
public void onPatSituation() {
JOptionPane.showMessageDialog(this, "Pat. It's a draw!");
JOptionPane.showMessageDialog(this.frame, "Pat. It's a draw!");
}
@Override
public void onSurrender(chess.model.Color color) {
JOptionPane.showMessageDialog(this, color + " has surrendered.");
JOptionPane.showMessageDialog(this.frame, color + " has surrendered.");
}
@Override
public void onGameEnd() {
JOptionPane.showMessageDialog(this, "End of the game");
this.dispose();
JOptionPane.showMessageDialog(this.frame, "End of the game");
this.frame.dispose();
this.commandExecutor.close();
}
@@ -259,8 +259,13 @@ public class Window extends JFrame implements GameListener, CommandSender {
*/
@Override
public void onPromotePawn(Coordinate pieceCoords) {
if (!showPopups)
Piece pawn = getPieceAt(pieceCoords);
chess.model.Color player = pawn.getColor();
if (hasAIAttached(player))
return;
SwingUtilities.invokeLater(() -> {
String result = null;
@@ -273,7 +278,7 @@ public class Window extends JFrame implements GameListener, CommandSender {
while (result == null || result.isEmpty()) {
result = (String) JOptionPane.showInputDialog(
this,
this.frame,
"Choose the type of piece to upgrade the pawn",
"Promote Dialog",
JOptionPane.PLAIN_MESSAGE,
@@ -301,9 +306,6 @@ public class Window extends JFrame implements GameListener, CommandSender {
updateBoard();
}
@Override
public void onMove(Move move, boolean captured) {}
@Override
public void onMoveNotAllowed(Move move) {
drawInvalid(move);
@@ -311,18 +313,16 @@ public class Window extends JFrame implements GameListener, CommandSender {
@Override
public void onDraw() {
JOptionPane.showMessageDialog(this, "Same position was repeated three times. It's a draw!");
JOptionPane.showMessageDialog(this.frame, "Same position was repeated three times. It's a draw!");
}
@Override
public void onCastling(boolean bigCastling, Move kingMove, Move rookMove) {}
@Override
public void onPawnPromoted(PromoteType promotion, Coordinate coordinate) {}
@Override
public CommandExecutor getCommandExecutor() {
return this.commandExecutor;
}
@Override
public void run() {
}
}