better gui interaction
This commit is contained in:
@@ -28,16 +28,19 @@ import chess.model.Piece;
|
|||||||
public class Window extends JFrame implements OutputSystem {
|
public class Window extends JFrame implements OutputSystem {
|
||||||
|
|
||||||
private final JLabel cells[][];
|
private final JLabel cells[][];
|
||||||
|
private final JLabel displayText;
|
||||||
private final CommandExecutor commandExecutor;
|
private final CommandExecutor commandExecutor;
|
||||||
|
|
||||||
private Coordinate lastClick = null;
|
private Coordinate lastClick = null;
|
||||||
|
|
||||||
public Window(CommandExecutor commandExecutor) {
|
public Window(CommandExecutor commandExecutor) {
|
||||||
this.cells = new JLabel[8][8];
|
this.cells = new JLabel[8][8];
|
||||||
|
this.displayText = new JLabel();
|
||||||
this.commandExecutor = commandExecutor;
|
this.commandExecutor = commandExecutor;
|
||||||
setSize(800, 800);
|
setSize(800, 870);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setLocationRelativeTo(null);
|
||||||
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandResult sendCommand(Command command) {
|
private CommandResult sendCommand(Command command) {
|
||||||
@@ -53,8 +56,14 @@ public class Window extends JFrame implements OutputSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buildBoard() {
|
private void buildBoard() {
|
||||||
JPanel content = new JPanel(new GridLayout(8, 8));
|
JPanel content = new JPanel();
|
||||||
|
JPanel grid = new JPanel(new GridLayout(8, 8));
|
||||||
|
|
||||||
|
content.add(this.displayText);
|
||||||
|
content.add(grid);
|
||||||
|
|
||||||
setContentPane(content);
|
setContentPane(content);
|
||||||
|
|
||||||
for (int y = 0; y < 8; y++) {
|
for (int y = 0; y < 8; y++) {
|
||||||
for (int x = 0; x < 8; x++) {
|
for (int x = 0; x < 8; x++) {
|
||||||
JLabel label = new JLabel();
|
JLabel label = new JLabel();
|
||||||
@@ -72,7 +81,7 @@ public class Window extends JFrame implements OutputSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
content.add(label);
|
grid.add(label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateBoard();
|
updateBoard();
|
||||||
@@ -151,13 +160,14 @@ public class Window extends JFrame implements OutputSystem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playerTurn(chess.model.Color color) {
|
public void playerTurn(chess.model.Color color) {
|
||||||
System.out.println("C'est au tour de " + color);
|
this.displayText.setText("C'est au tour de " + color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void winnerIs(chess.model.Color color) {
|
public void winnerIs(chess.model.Color color) {
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
JOptionPane.showMessageDialog(this, "Victoire de " + color);
|
JOptionPane.showMessageDialog(this, "Victoire de " + color);
|
||||||
|
this.dispose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,9 +207,6 @@ public class Window extends JFrame implements OutputSystem {
|
|||||||
@Override
|
@Override
|
||||||
public void promotePawn(Coordinate pieceCoords) {
|
public void promotePawn(Coordinate pieceCoords) {
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
// String result = JOptionPane.showInputDialog(this, "Choisissez le type !");
|
|
||||||
// sendCommand(new PromoteCommand(PromoteType.Queen, pieceCoords));
|
|
||||||
|
|
||||||
String result = null;
|
String result = null;
|
||||||
|
|
||||||
Object[] possibilities = new Object[PromoteType.values().length];
|
Object[] possibilities = new Object[PromoteType.values().length];
|
||||||
|
|||||||
Reference in New Issue
Block a user