feat: add undo
This commit is contained in:
@@ -6,6 +6,7 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
@@ -13,31 +14,38 @@ import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import chess.controller.Command;
|
||||
import chess.controller.Command.CommandResult;
|
||||
import chess.controller.CommandExecutor;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.Command.CommandResult;
|
||||
import chess.controller.commands.CastlingCommand;
|
||||
import chess.controller.commands.GetAllowedMovesCommand;
|
||||
import chess.controller.commands.GetPieceAtCommand;
|
||||
import chess.controller.commands.GrandCastlingCommand;
|
||||
import chess.controller.commands.MoveCommand;
|
||||
import chess.controller.commands.PromoteCommand;
|
||||
import chess.controller.commands.PromoteCommand.PromoteType;
|
||||
import chess.controller.commands.UndoCommand;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Move;
|
||||
import chess.model.Piece;
|
||||
|
||||
public class Window extends JFrame implements OutputSystem {
|
||||
|
||||
private final JLabel cells[][];
|
||||
private final JLabel displayText;
|
||||
private final CommandExecutor commandExecutor;
|
||||
|
||||
private Coordinate lastClick = null;
|
||||
|
||||
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");
|
||||
|
||||
public Window(CommandExecutor commandExecutor) {
|
||||
this.cells = new JLabel[8][8];
|
||||
this.displayText = new JLabel();
|
||||
this.commandExecutor = commandExecutor;
|
||||
setSize(800, 870);
|
||||
setSize(800, 910);
|
||||
setVisible(true);
|
||||
setLocationRelativeTo(null);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
@@ -51,12 +59,34 @@ public class Window extends JFrame implements OutputSystem {
|
||||
return ((x + y) % 2 == 1) ? Color.BLACK : Color.WHITE;
|
||||
}
|
||||
|
||||
private void buildButtons(JPanel bottom) {
|
||||
castlingButton.addActionListener((event) -> {
|
||||
sendCommand(new CastlingCommand());
|
||||
});
|
||||
|
||||
bigCastlingButton.addActionListener((event) -> {
|
||||
sendCommand(new GrandCastlingCommand());
|
||||
});
|
||||
|
||||
undoButton.addActionListener((event) -> {
|
||||
sendCommand(new UndoCommand());
|
||||
});
|
||||
|
||||
bottom.add(castlingButton);
|
||||
bottom.add(bigCastlingButton);
|
||||
bottom.add(undoButton);
|
||||
}
|
||||
|
||||
private void buildBoard() {
|
||||
JPanel content = new JPanel();
|
||||
JPanel grid = new JPanel(new GridLayout(8, 8));
|
||||
JPanel bottom = new JPanel();
|
||||
|
||||
buildButtons(bottom);
|
||||
|
||||
content.add(this.displayText);
|
||||
content.add(grid);
|
||||
content.add(bottom);
|
||||
|
||||
setContentPane(content);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user