Added resign and draw feature
parent
3c3dd5e8ab
commit
aaa4317c9c
|
@ -122,6 +122,45 @@ public class GameController {
|
||||||
// 3. Board neu zeichnen
|
// 3. Board neu zeichnen
|
||||||
updateGuiBoard();
|
updateGuiBoard();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// --- AUFGEBEN-BUTTON ---
|
||||||
|
gui.getResignButton().addActionListener(e -> {
|
||||||
|
if (gameOver) return; // Nichts tun wenn Spiel vorbei
|
||||||
|
|
||||||
|
int answer = javax.swing.JOptionPane.showConfirmDialog(
|
||||||
|
null,
|
||||||
|
"Willst du wirklich aufgeben?",
|
||||||
|
"Aufgeben",
|
||||||
|
javax.swing.JOptionPane.YES_NO_OPTION
|
||||||
|
);
|
||||||
|
if (answer == javax.swing.JOptionPane.YES_OPTION) {
|
||||||
|
gameOver = true;
|
||||||
|
String winner = engine.getCurrentPlayer().equals("WHITE") ? "SCHWARZ" : "WEIß";
|
||||||
|
gui.displayMessage(winner + " gewinnt durch Aufgabe!");
|
||||||
|
engine.getWhiteTimer().stop();
|
||||||
|
engine.getBlackTimer().stop();
|
||||||
|
askForRestart();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// --- PATT-/REMIS-BUTTON ---
|
||||||
|
gui.getDrawButton().addActionListener(e -> {
|
||||||
|
if (gameOver) return;
|
||||||
|
|
||||||
|
int answer = javax.swing.JOptionPane.showConfirmDialog(
|
||||||
|
null,
|
||||||
|
"Remis anbieten? (Das Spiel endet sofort unentschieden)",
|
||||||
|
"Remis",
|
||||||
|
javax.swing.JOptionPane.YES_NO_OPTION
|
||||||
|
);
|
||||||
|
if (answer == javax.swing.JOptionPane.YES_OPTION) {
|
||||||
|
gameOver = true;
|
||||||
|
gui.displayMessage("Remis! (durch Einigung)");
|
||||||
|
engine.getWhiteTimer().stop();
|
||||||
|
engine.getBlackTimer().stop();
|
||||||
|
askForRestart();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class GameGui {
|
||||||
|
|
||||||
private JButton resignButton;
|
private JButton resignButton;
|
||||||
private JButton drawButton;
|
private JButton drawButton;
|
||||||
|
private JButton quickSaveButton;
|
||||||
|
|
||||||
Color LIGHT = new Color(0xe0e1dd);
|
Color LIGHT = new Color(0xe0e1dd);
|
||||||
Color DARK = new Color(0x778da9);
|
Color DARK = new Color(0x778da9);
|
||||||
|
@ -173,16 +174,16 @@ public class GameGui {
|
||||||
buttonRow.setOpaque(false);
|
buttonRow.setOpaque(false);
|
||||||
buttonRow.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 10, 0));
|
buttonRow.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 10, 0));
|
||||||
|
|
||||||
resignButton = new JButton("🛑");
|
resignButton = new JButton("🏳");
|
||||||
resignButton.setPreferredSize(new Dimension(70, 70));
|
resignButton.setPreferredSize(new Dimension(70, 70));
|
||||||
resignButton.setFont(new Font("SansSerif", Font.BOLD, 40));
|
resignButton.setFont(new Font("SansSerif", Font.BOLD, 35));
|
||||||
resignButton.setBackground(new Color(0xff0044));
|
resignButton.setBackground(new Color(0xff0044));
|
||||||
resignButton.setForeground(Color.WHITE);
|
resignButton.setForeground(Color.WHITE);
|
||||||
resignButton.setFocusPainted(false);
|
resignButton.setFocusPainted(false);
|
||||||
|
|
||||||
drawButton = new JButton("½–½");
|
drawButton = new JButton("½");
|
||||||
drawButton.setPreferredSize(new Dimension(70, 70));
|
drawButton.setPreferredSize(new Dimension(70, 70));
|
||||||
drawButton.setFont(new Font("SansSerif", Font.BOLD, 40));
|
drawButton.setFont(new Font("SansSerif", Font.BOLD, 35));
|
||||||
drawButton.setBackground(new Color(0x0080ff));
|
drawButton.setBackground(new Color(0x0080ff));
|
||||||
drawButton.setForeground(Color.WHITE);
|
drawButton.setForeground(Color.WHITE);
|
||||||
drawButton.setFocusPainted(false);
|
drawButton.setFocusPainted(false);
|
||||||
|
|
Loading…
Reference in New Issue