From a506f2230da83fcb9a07186649405242578a35c9 Mon Sep 17 00:00:00 2001 From: dstuck Date: Tue, 24 Jun 2025 14:05:02 +0200 Subject: [PATCH] add rudementary quicksave -load --- .../controller/ButtonQuickloadListener.java | 24 + .../controller/ButtonQuicksaveListener.java | 19 + .../de/mannheim/th/chess/domain/Game.java | 22 +- .../de/mannheim/th/chess/ui/SpielFrame.java | 880 +++++++++--------- 4 files changed, 508 insertions(+), 437 deletions(-) create mode 100644 src/main/java/de/mannheim/th/chess/controller/ButtonQuickloadListener.java create mode 100644 src/main/java/de/mannheim/th/chess/controller/ButtonQuicksaveListener.java diff --git a/src/main/java/de/mannheim/th/chess/controller/ButtonQuickloadListener.java b/src/main/java/de/mannheim/th/chess/controller/ButtonQuickloadListener.java new file mode 100644 index 0000000..c1cf05b --- /dev/null +++ b/src/main/java/de/mannheim/th/chess/controller/ButtonQuickloadListener.java @@ -0,0 +1,24 @@ + +package de.mannheim.th.chess.controller; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import de.mannheim.th.chess.domain.Game; +import de.mannheim.th.chess.ui.SpielFrame; + +public class ButtonQuickloadListener implements ActionListener { + private Game game; + private SpielFrame sf; + + public ButtonQuickloadListener(Game game, SpielFrame sf) { + this.game = game; + this.sf = sf; + } + + @Override + public void actionPerformed(ActionEvent e) { + this.game.quickload(); + this.sf.erstelleBrett(); + } +} diff --git a/src/main/java/de/mannheim/th/chess/controller/ButtonQuicksaveListener.java b/src/main/java/de/mannheim/th/chess/controller/ButtonQuicksaveListener.java new file mode 100644 index 0000000..c73facc --- /dev/null +++ b/src/main/java/de/mannheim/th/chess/controller/ButtonQuicksaveListener.java @@ -0,0 +1,19 @@ +package de.mannheim.th.chess.controller; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import de.mannheim.th.chess.domain.Game; + +public class ButtonQuicksaveListener implements ActionListener { + private Game game; + + public ButtonQuicksaveListener(Game game) { + this.game = game; + } + + @Override + public void actionPerformed(ActionEvent e) { + this.game.quicksave(); + } +} diff --git a/src/main/java/de/mannheim/th/chess/domain/Game.java b/src/main/java/de/mannheim/th/chess/domain/Game.java index a65305b..d353a3e 100644 --- a/src/main/java/de/mannheim/th/chess/domain/Game.java +++ b/src/main/java/de/mannheim/th/chess/domain/Game.java @@ -33,6 +33,8 @@ public class Game { private String modus; private boolean rotieren, zuruecknahme; + private MoveList savestate; + private MoveList movelist; public Game() { @@ -123,6 +125,20 @@ public class Game { this.movelist.removeLast(); } + public void quicksave() { + logger.info("Quicksaved"); + this.savestate = new MoveList(this.movelist); + } + + public void quickload() { + logger.info("Quickloaded"); + + this.board = new Board(); + for (Move move : savestate) { + this.playMove(move); + } + } + /** * Plays the move on the board and adds it to the movelist * @@ -272,9 +288,9 @@ public class Game { return board.getFen(); } -// public Square getSelectedSquare() { -// return this.getSelectedSquare(); -// } + // public Square getSelectedSquare() { + // return this.getSelectedSquare(); + // } public String getUnicodeFromMove(Move move) { return board.getPiece(move.getTo()).getFanSymbol().toUpperCase(); diff --git a/src/main/java/de/mannheim/th/chess/ui/SpielFrame.java b/src/main/java/de/mannheim/th/chess/ui/SpielFrame.java index 5dcd7b3..ee3f457 100644 --- a/src/main/java/de/mannheim/th/chess/ui/SpielFrame.java +++ b/src/main/java/de/mannheim/th/chess/ui/SpielFrame.java @@ -14,6 +14,8 @@ import de.mannheim.th.chess.utl.Clock; import de.mannheim.th.chess.controller.ButtonAufgebenListener; import de.mannheim.th.chess.controller.ButtonFileSaverListener; import de.mannheim.th.chess.controller.ButtonMovePieceListener; +import de.mannheim.th.chess.controller.ButtonQuickloadListener; +import de.mannheim.th.chess.controller.ButtonQuicksaveListener; import de.mannheim.th.chess.controller.ButtonSelectPieceListener; import de.mannheim.th.chess.controller.ButtonToNormalListener; import de.mannheim.th.chess.controller.ButtonUndoMoveListener; @@ -44,492 +46,502 @@ import java.awt.GridLayout; public class SpielFrame extends JFrame { - private static final Logger logger = LogManager.getLogger(App.class); + private static final Logger logger = LogManager.getLogger(App.class); - private static final long serialVersionUID = 1L; - private ArrayList buttons = new ArrayList<>(); - private HashMap belegungen = new HashMap<>(); - private JPanel panelLinks, panelRechts, contentPane; - private JButton undo, undo2; - private JTextArea ausgabe; - private Game game; - private Clock clock; - private ArrayList anzeigeMoves = new ArrayList(); - - private BoardMode mode; - private Square selectedSquare; - - public enum BoardMode { - normal, pieceSelected, finished - } - - /** - * Create the frame. - */ - public SpielFrame(Game game) { - - this.game = game; - this.clock = game.getClock(); - this.clock.start(); - - mode = BoardMode.normal; - - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(100, 100, 1920, 1080); - setTitle("Schach"); - setAlwaysOnTop(true); - - contentPane = new JPanel(); - contentPane.setLayout(new BorderLayout()); - setContentPane(contentPane); - - // Linkes Panel mit GridLayout 8x8 für Schachbrett - panelLinks = new JPanel(new GridLayout(8, 8)); - - erstelleBrett(); - - // Rechtes Panel für Steuerung oder zusätzliche Eingaben - panelRechts = new JPanel(); - panelRechts.setBackground(new Color(90, 90, 90)); - panelRechts.setLayout(new BoxLayout(panelRechts, BoxLayout.Y_AXIS)); - - // Panel für alle Eingaben von Player 2 - panelRechts.add(getUiPlayerTwo()); - - // Panel für Statistikanzeigen - panelRechts.add(getUiStatistik()); - - // Panel für alle Eingaben von Player 1 - panelRechts.add(getUiPlayerOne()); - - // JSplitPane horizontal (linke und rechte Hälfte) - JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panelLinks, panelRechts); - splitPane.setResizeWeight(0.75); - splitPane.setBackground(Color.BLACK); - splitPane.setDividerSize(1); - splitPane.setEnabled(false); - - contentPane.add(splitPane, BorderLayout.CENTER); - - setVisible(true); - } - - /** - * Erstellt alle Buttons und fügt sie dem Frame hinzu. - */ - public void erstelleBrett() { - - this.clearButtons(); - this.setDefaultBackground(); - this.setButtonsActions(); - - ladeBrett(); - - panelLinks.revalidate(); - panelLinks.repaint(); - - } - - private int mirrowedGrid(int i) { - return 63 - (((i / 8) * 8) + (7 - i % 8)); - } - - /** - * holt sich FEN-Zeichenkette und extrahiert daraus die Positionen der Figuren - */ - private void ladeBrett() { - // System.out.println(game.toFEN()); - - char[] fen = game.toFEN().replaceAll("/", "").split(" ")[0].toCharArray(); - int i = 0; - for (int j = 0; j < fen.length; j++) { - if (Character.isDigit(fen[j])) { - int leerfelder = Character.getNumericValue(fen[j]); - for (int k = 0; k < leerfelder; k++) { - belegungen.put(buttons.get(i), "n-n"); - // buttons.get(i).setEnabled(false); // erstmal deaktivieren, weil leere Felder - // nicht ckickbar sein sollten. - i++; - } - continue; - } else if (fen[j] >= 65 && fen[j] <= 90) { // ein Großbuchstabe, also - belegungen.put(buttons.get(i), "w-" + fen[j]); - } else if (fen[j] >= 97 && fen[j] <= 122) { // ein Kleinbuchstabe, also - belegungen.put(buttons.get(i), "b-" + fen[j]); - // buttons.get(i).setEnabled(false); // erstmal deaktivieren, damit weiß - // beginnen kann - } - buttons.get(i).setIcon(new ImageIcon("src/main/resources/" + (int) fen[j] + ".png")); - buttons.get(i).setDisabledIcon(new ImageIcon("src/main/resources/" + (int) fen[j] + ".png")); - - i++; - - } - } - - /** - * Clears the existing buttons from the button list, panellinks and fills them - * with new blank ones. - */ - private void clearButtons() { - - buttons.clear(); - panelLinks.removeAll(); - - for (int i = 0; i < 64; i++) { - JButton b = new JButton(); - - b.setEnabled(false); - - // style - b.setFocusPainted(false); - b.setFont(new Font("Arial", Font.PLAIN, 30)); - b.setForeground(Color.WHITE); - b.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); - b.setName(i + ""); - - buttons.add(b); - } - } - - /** - * Sets the default background color for the buttons in the grid. - */ - private void setDefaultBackground() { - for (int i = 0; i < 64; i++) { - JButton b = buttons.get(i); - if ((i / 8 + i % 8) % 2 == 0) { - // logger.info("Helles Feld erstellt." + i); - b.setBackground(new Color(90, 90, 90)); - } else { - // logger.info("Dunkles Feld erstellt." + i); - b.setBackground(new Color(65, 65, 65)); - } - } - } - - /* - * Switches the button actions depending on the boardmode - */ - private void setButtonsActions() { - - List selectables; - - switch (this.mode) { - case BoardMode.normal: - - selectables = game.getAllLegalMoveableSquares(); - - for (Square square : selectables) { - JButton b = buttons.get(mirrowedGrid(square.ordinal())); - b.setEnabled(true); - // b.setBackground(Color.green); - b.addActionListener(new ButtonSelectPieceListener(this, square)); - } - - break; - - case BoardMode.pieceSelected: - - JButton s = buttons.get(mirrowedGrid(selectedSquare.ordinal())); - s.setEnabled(true); - s.setBackground(new Color(165, 42, 42)); - s.addActionListener(new ButtonToNormalListener(this)); - - selectables = game.getLegalMoveableSquares(selectedSquare); - - for (Square square : selectables) { - JButton b = buttons.get(mirrowedGrid(square.ordinal())); - final Move move = new Move(selectedSquare, square); - b.setEnabled(true); - b.setBackground(new Color(230, 100, 100)); - b.addActionListener(new ButtonMovePieceListener(this, this.game, move)); - } - break; - case finished: - clearButtons(); - break; - default: - break; - - } - - for (JButton b : buttons) { - panelLinks.add(b); - } - } - - public void showDraw() { - JFrame frame = new JFrame("Result"); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setSize(300, 150); - frame.setLayout(null); - - // JLabel jl = new JLabel(String.format("%d - %d", player / 2, player % 2)); - // jl.setBounds(50, 30, 200, 25); - // jl.setFont(new Font("Tahoma", Font.BOLD, 20)); - // frame.add(jl); - // frame.setVisible(true); - } - - public void showWin(int player) { - JFrame frame = new JFrame("Result"); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setSize(300, 150); - frame.setLayout(null); - - JLabel jl = new JLabel(String.format("%d - %d", player / 2, player % 2)); - jl.setBounds(50, 30, 200, 25); - jl.setFont(new Font("Tahoma", Font.BOLD, 20)); - frame.add(jl); - frame.setVisible(true); - } - - public int showPromotion() { - final int[] result = { -1 }; - - JDialog dialog = new JDialog(this, "Wähle eine Figur", true); - dialog.setLayout(new GridLayout(2, 2)); - dialog.setSize(300, 200); - - int[] pictures = { 81, 82, 66, 78, 113, 114, 98, 110 }; - - for (int i = 0; i < 4; i++) { - int index = (game.getActivePlayer() - 1) * 4 + i; - JButton jb = new JButton(); - jb.setIcon(new ImageIcon("src/main/resources/" + pictures[index] + ".png")); - int selectedPiece = index; - jb.addActionListener(e -> { - System.out.println("Test"); - result[0] = selectedPiece; - dialog.dispose(); - }); - dialog.add(jb); - } - - dialog.setLocationRelativeTo(null); - dialog.setVisible(true); - - return result[0]; - } + private static final long serialVersionUID = 1L; + private ArrayList buttons = new ArrayList<>(); + private HashMap belegungen = new HashMap<>(); + private JPanel panelLinks, panelRechts, contentPane; + private JButton undo, undo2; + private JTextArea ausgabe; + private Game game; + private Clock clock; + private ArrayList anzeigeMoves = new ArrayList(); + + private BoardMode mode; + private Square selectedSquare; + + public enum BoardMode { + normal, pieceSelected, finished + } + + /** + * Create the frame. + */ + public SpielFrame(Game game) { + + this.game = game; + this.clock = game.getClock(); + this.clock.start(); + + mode = BoardMode.normal; + + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(100, 100, 1920, 1080); + setTitle("Schach"); + setAlwaysOnTop(true); + + contentPane = new JPanel(); + contentPane.setLayout(new BorderLayout()); + setContentPane(contentPane); + + // Linkes Panel mit GridLayout 8x8 für Schachbrett + panelLinks = new JPanel(new GridLayout(8, 8)); + + erstelleBrett(); + + // Rechtes Panel für Steuerung oder zusätzliche Eingaben + panelRechts = new JPanel(); + panelRechts.setBackground(new Color(90, 90, 90)); + panelRechts.setLayout(new BoxLayout(panelRechts, BoxLayout.Y_AXIS)); + + // Panel für alle Eingaben von Player 2 + panelRechts.add(getUiPlayerTwo()); + + // Panel für Statistikanzeigen + panelRechts.add(getUiStatistik()); + + // Panel für alle Eingaben von Player 1 + panelRechts.add(getUiPlayerOne()); + + // JSplitPane horizontal (linke und rechte Hälfte) + JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panelLinks, panelRechts); + splitPane.setResizeWeight(0.75); + splitPane.setBackground(Color.BLACK); + splitPane.setDividerSize(1); + splitPane.setEnabled(false); + + contentPane.add(splitPane, BorderLayout.CENTER); + + setVisible(true); + } + + /** + * Erstellt alle Buttons und fügt sie dem Frame hinzu. + */ + public void erstelleBrett() { + + this.clearButtons(); + this.setDefaultBackground(); + this.setButtonsActions(); + + ladeBrett(); + + panelLinks.revalidate(); + panelLinks.repaint(); + + } + + private int mirrowedGrid(int i) { + return 63 - (((i / 8) * 8) + (7 - i % 8)); + } + + /** + * holt sich FEN-Zeichenkette und extrahiert daraus die Positionen der Figuren + */ + private void ladeBrett() { + // System.out.println(game.toFEN()); + + char[] fen = game.toFEN().replaceAll("/", "").split(" ")[0].toCharArray(); + int i = 0; + for (int j = 0; j < fen.length; j++) { + if (Character.isDigit(fen[j])) { + int leerfelder = Character.getNumericValue(fen[j]); + for (int k = 0; k < leerfelder; k++) { + belegungen.put(buttons.get(i), "n-n"); + // buttons.get(i).setEnabled(false); // erstmal deaktivieren, weil leere Felder + // nicht ckickbar sein sollten. + i++; + } + continue; + } else if (fen[j] >= 65 && fen[j] <= 90) { // ein Großbuchstabe, also + belegungen.put(buttons.get(i), "w-" + fen[j]); + } else if (fen[j] >= 97 && fen[j] <= 122) { // ein Kleinbuchstabe, also + belegungen.put(buttons.get(i), "b-" + fen[j]); + // buttons.get(i).setEnabled(false); // erstmal deaktivieren, damit weiß + // beginnen kann + } + buttons.get(i).setIcon(new ImageIcon("src/main/resources/" + (int) fen[j] + ".png")); + buttons.get(i).setDisabledIcon(new ImageIcon("src/main/resources/" + (int) fen[j] + ".png")); + + i++; + + } + } + + /** + * Clears the existing buttons from the button list, panellinks and fills them + * with new blank ones. + */ + private void clearButtons() { + + buttons.clear(); + panelLinks.removeAll(); + + for (int i = 0; i < 64; i++) { + JButton b = new JButton(); + + b.setEnabled(false); + + // style + b.setFocusPainted(false); + b.setFont(new Font("Arial", Font.PLAIN, 30)); + b.setForeground(Color.WHITE); + b.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); + b.setName(i + ""); + + buttons.add(b); + } + } + + /** + * Sets the default background color for the buttons in the grid. + */ + private void setDefaultBackground() { + for (int i = 0; i < 64; i++) { + JButton b = buttons.get(i); + if ((i / 8 + i % 8) % 2 == 0) { + // logger.info("Helles Feld erstellt." + i); + b.setBackground(new Color(90, 90, 90)); + } else { + // logger.info("Dunkles Feld erstellt." + i); + b.setBackground(new Color(65, 65, 65)); + } + } + } + + /* + * Switches the button actions depending on the boardmode + */ + private void setButtonsActions() { + + List selectables; + + switch (this.mode) { + case BoardMode.normal: + + selectables = game.getAllLegalMoveableSquares(); + + for (Square square : selectables) { + JButton b = buttons.get(mirrowedGrid(square.ordinal())); + b.setEnabled(true); + // b.setBackground(Color.green); + b.addActionListener(new ButtonSelectPieceListener(this, square)); + } + + break; + + case BoardMode.pieceSelected: + + JButton s = buttons.get(mirrowedGrid(selectedSquare.ordinal())); + s.setEnabled(true); + s.setBackground(new Color(165, 42, 42)); + s.addActionListener(new ButtonToNormalListener(this)); + + selectables = game.getLegalMoveableSquares(selectedSquare); + + for (Square square : selectables) { + JButton b = buttons.get(mirrowedGrid(square.ordinal())); + final Move move = new Move(selectedSquare, square); + b.setEnabled(true); + b.setBackground(new Color(230, 100, 100)); + b.addActionListener(new ButtonMovePieceListener(this, this.game, move)); + } + break; + case finished: + clearButtons(); + break; + default: + break; + + } + + for (JButton b : buttons) { + panelLinks.add(b); + } + } + + public void showDraw() { + JFrame frame = new JFrame("Result"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(300, 150); + frame.setLayout(null); + + // JLabel jl = new JLabel(String.format("%d - %d", player / 2, player % 2)); + // jl.setBounds(50, 30, 200, 25); + // jl.setFont(new Font("Tahoma", Font.BOLD, 20)); + // frame.add(jl); + // frame.setVisible(true); + } + + public void showWin(int player) { + JFrame frame = new JFrame("Result"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(300, 150); + frame.setLayout(null); + + JLabel jl = new JLabel(String.format("%d - %d", player / 2, player % 2)); + jl.setBounds(50, 30, 200, 25); + jl.setFont(new Font("Tahoma", Font.BOLD, 20)); + frame.add(jl); + frame.setVisible(true); + } + + public int showPromotion() { + final int[] result = { -1 }; + + JDialog dialog = new JDialog(this, "Wähle eine Figur", true); + dialog.setLayout(new GridLayout(2, 2)); + dialog.setSize(300, 200); + + int[] pictures = { 81, 82, 66, 78, 113, 114, 98, 110 }; + + for (int i = 0; i < 4; i++) { + int index = (game.getActivePlayer() - 1) * 4 + i; + JButton jb = new JButton(); + jb.setIcon(new ImageIcon("src/main/resources/" + pictures[index] + ".png")); + int selectedPiece = index; + jb.addActionListener(e -> { + System.out.println("Test"); + result[0] = selectedPiece; + dialog.dispose(); + }); + dialog.add(jb); + } + + dialog.setLocationRelativeTo(null); + dialog.setVisible(true); + + return result[0]; + } + + private JPanel getUiPlayerTwo() { + + JPanel playerTwo = new JPanel(); + playerTwo.setBackground(new Color(90, 90, 90)); + playerTwo.setLayout(new BoxLayout(playerTwo, BoxLayout.Y_AXIS)); + + playerTwo.add(Box.createVerticalStrut(15)); + + JLabel pl2 = new JLabel("Player 2:"); + pl2.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); + pl2.setFont(new Font("Calibri", Font.BOLD, 35)); + pl2.setForeground(Color.BLACK); + pl2.setAlignmentX(Component.CENTER_ALIGNMENT); + playerTwo.add(pl2); + + playerTwo.add(Box.createVerticalStrut(10)); + + JLabel clock1 = clock.getClock2(); + playerTwo.add(clock1); + + playerTwo.add(Box.createVerticalStrut(10)); + + // Button zurücknahme und aufgeben für Player 2 + JPanel aufgebenUndo = new JPanel(); + aufgebenUndo.setBackground(new Color(90, 90, 90)); + aufgebenUndo.setLayout(new BoxLayout(aufgebenUndo, BoxLayout.X_AXIS)); + + if (game.isZuruecknahme()) { + undo = new JButton("Zug zurücknehmen"); + undo.setBackground(Color.LIGHT_GRAY); + undo.setForeground(Color.BLACK); + undo.setFont(new Font("Tahoma", Font.BOLD, 16)); + undo.setAlignmentX(Component.CENTER_ALIGNMENT); + aufgebenUndo.add(undo); - private JPanel getUiPlayerTwo() { - - JPanel playerTwo = new JPanel(); - playerTwo.setBackground(new Color(90, 90, 90)); - playerTwo.setLayout(new BoxLayout(playerTwo, BoxLayout.Y_AXIS)); - - playerTwo.add(Box.createVerticalStrut(15)); - - JLabel pl2 = new JLabel("Player 2:"); - pl2.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); - pl2.setFont(new Font("Calibri", Font.BOLD, 35)); - pl2.setForeground(Color.BLACK); - pl2.setAlignmentX(Component.CENTER_ALIGNMENT); - playerTwo.add(pl2); - - playerTwo.add(Box.createVerticalStrut(10)); - - JLabel clock1 = clock.getClock2(); - playerTwo.add(clock1); - - playerTwo.add(Box.createVerticalStrut(10)); - - // Button zurücknahme und aufgeben für Player 2 - JPanel aufgebenUndo = new JPanel(); - aufgebenUndo.setBackground(new Color(90, 90, 90)); - aufgebenUndo.setLayout(new BoxLayout(aufgebenUndo, BoxLayout.X_AXIS)); - - if (game.isZuruecknahme()) { - undo = new JButton("Zug zurücknehmen"); - undo.setBackground(Color.LIGHT_GRAY); - undo.setForeground(Color.BLACK); - undo.setFont(new Font("Tahoma", Font.BOLD, 16)); - undo.setAlignmentX(Component.CENTER_ALIGNMENT); - aufgebenUndo.add(undo); + // Button-Listener + undo.addActionListener(new ButtonUndoMoveListener(this, this.game)); + } - // Button-Listener - undo.addActionListener(new ButtonUndoMoveListener(this, this.game)); - } + aufgebenUndo.add(Box.createHorizontalStrut(10)); - aufgebenUndo.add(Box.createHorizontalStrut(10)); + JButton aufgeben = new JButton("Aufgeben"); + aufgeben.setBackground(Color.LIGHT_GRAY); + aufgeben.setForeground(Color.BLACK); + aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16)); + aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT); + aufgebenUndo.add(aufgeben); - JButton aufgeben = new JButton("Aufgeben"); - aufgeben.setBackground(Color.LIGHT_GRAY); - aufgeben.setForeground(Color.BLACK); - aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16)); - aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT); - aufgebenUndo.add(aufgeben); + // Button-Listener + aufgeben.addActionListener(new ButtonAufgebenListener()); - // Button-Listener - aufgeben.addActionListener(new ButtonAufgebenListener()); + aufgebenUndo.add(Box.createHorizontalStrut(10)); - aufgebenUndo.add(Box.createHorizontalStrut(10)); + JButton safe = new JButton("Spielstand sichern"); + safe.setBackground(Color.LIGHT_GRAY); + safe.setForeground(Color.BLACK); + safe.setFont(new Font("Tahoma", Font.BOLD, 16)); + safe.setAlignmentX(Component.CENTER_ALIGNMENT); + aufgebenUndo.add(safe); - JButton safe = new JButton("Spielstand sichern"); - safe.setBackground(Color.LIGHT_GRAY); - safe.setForeground(Color.BLACK); - safe.setFont(new Font("Tahoma", Font.BOLD, 16)); - safe.setAlignmentX(Component.CENTER_ALIGNMENT); - aufgebenUndo.add(safe); + // Button-Listener + safe.addActionListener(new ButtonFileSaverListener(this, this.game)); - // Button-Listener - safe.addActionListener(new ButtonFileSaverListener(this, this.game)); + playerTwo.add(aufgebenUndo); - playerTwo.add(aufgebenUndo); + playerTwo.add(Box.createVerticalStrut(10)); - playerTwo.add(Box.createVerticalStrut(10)); + return playerTwo; + } - return playerTwo; - } + private JPanel getUiStatistik() { - private JPanel getUiStatistik() { + JPanel statistik = new JPanel(); + statistik.setBackground(new Color(90, 90, 90)); + statistik.setLayout(new BoxLayout(statistik, BoxLayout.Y_AXIS)); - JPanel statistik = new JPanel(); - statistik.setBackground(new Color(90, 90, 90)); - statistik.setLayout(new BoxLayout(statistik, BoxLayout.Y_AXIS)); + ausgabe = new JTextArea(); + ausgabe.setEditable(false); + ausgabe.setBackground(new Color(75, 75, 75)); + ausgabe.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); + ausgabe.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 20)); + ausgabe.setForeground(Color.BLACK); + ausgabe.setText("\n Bisherige Züge:\n"); - ausgabe = new JTextArea(); - ausgabe.setEditable(false); - ausgabe.setBackground(new Color(75, 75, 75)); - ausgabe.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); - ausgabe.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 20)); - ausgabe.setForeground(Color.BLACK); - ausgabe.setText("\n Bisherige Züge:\n"); + JScrollPane scrollPane = new JScrollPane(ausgabe); + scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - JScrollPane scrollPane = new JScrollPane(ausgabe); - scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + statistik.add(scrollPane); - statistik.add(scrollPane); + JButton quicksave = new JButton(); + quicksave.addActionListener(new ButtonQuicksaveListener(this.game)); + quicksave.setText("Quicksave"); + statistik.add(quicksave); - return statistik; - } + JButton quickload = new JButton(); + quickload.addActionListener(new ButtonQuickloadListener(this.game, this)); + quickload.setText("Quickload"); + statistik.add(quickload); - public void aktualisiereAusgabe() { + return statistik; + } - StringBuilder sb = new StringBuilder(); - sb.append("\n Bisherige Züge:\n"); + public void aktualisiereAusgabe() { - MoveList l = game.getMoveList(); - anzeigeMoves.add(" " + game.getUnicodeFromMove(l.getLast()) + ": " + l.getLast().toString() + "\n"); + StringBuilder sb = new StringBuilder(); + sb.append("\n Bisherige Züge:\n"); - for (String line : anzeigeMoves) { - sb.append(line); - } + MoveList l = game.getMoveList(); + anzeigeMoves.add(" " + game.getUnicodeFromMove(l.getLast()) + ": " + l.getLast().toString() + "\n"); - ausgabe.setText(sb.toString()); - } + for (String line : anzeigeMoves) { + sb.append(line); + } - public void deleteLastAusgabe() { - String[] zeilen = ausgabe.getText().split("\n"); + ausgabe.setText(sb.toString()); + } - // es müssen immer mind 5 Zeilen existieren, dass also 1 Zug löschbar ist - if (zeilen.length <= 2) - return; + public void deleteLastAusgabe() { + String[] zeilen = ausgabe.getText().split("\n"); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < zeilen.length - 1; i++) { - sb.append(zeilen[i]).append("\n"); - } + // es müssen immer mind 5 Zeilen existieren, dass also 1 Zug löschbar ist + if (zeilen.length <= 2) + return; - ausgabe.setText(sb.toString()); - } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < zeilen.length - 1; i++) { + sb.append(zeilen[i]).append("\n"); + } - private JPanel getUiPlayerOne() { + ausgabe.setText(sb.toString()); + } - JPanel playerOne = new JPanel(); - playerOne.setBackground(new Color(90, 90, 90)); - playerOne.setLayout(new BoxLayout(playerOne, BoxLayout.Y_AXIS)); + private JPanel getUiPlayerOne() { - playerOne.add(Box.createVerticalStrut(10)); + JPanel playerOne = new JPanel(); + playerOne.setBackground(new Color(90, 90, 90)); + playerOne.setLayout(new BoxLayout(playerOne, BoxLayout.Y_AXIS)); - // Button zurücknahme und aufgeben für Player 1 - JPanel aufgebenUndo = new JPanel(); - aufgebenUndo.setBackground(new Color(90, 90, 90)); - aufgebenUndo.setLayout(new BoxLayout(aufgebenUndo, BoxLayout.X_AXIS)); + playerOne.add(Box.createVerticalStrut(10)); - if (game.isZuruecknahme()) { - undo2 = new JButton("Zug zurücknehmen"); - undo2.setBackground(Color.LIGHT_GRAY); - undo2.setForeground(Color.BLACK); - undo2.setFont(new Font("Tahoma", Font.BOLD, 16)); - undo2.setAlignmentX(Component.CENTER_ALIGNMENT); - aufgebenUndo.add(undo2); + // Button zurücknahme und aufgeben für Player 1 + JPanel aufgebenUndo = new JPanel(); + aufgebenUndo.setBackground(new Color(90, 90, 90)); + aufgebenUndo.setLayout(new BoxLayout(aufgebenUndo, BoxLayout.X_AXIS)); - // Button-Listener - undo2.addActionListener(new ButtonUndoMoveListener(this, this.game)); + if (game.isZuruecknahme()) { + undo2 = new JButton("Zug zurücknehmen"); + undo2.setBackground(Color.LIGHT_GRAY); + undo2.setForeground(Color.BLACK); + undo2.setFont(new Font("Tahoma", Font.BOLD, 16)); + undo2.setAlignmentX(Component.CENTER_ALIGNMENT); + aufgebenUndo.add(undo2); - } + // Button-Listener + undo2.addActionListener(new ButtonUndoMoveListener(this, this.game)); - aufgebenUndo.add(Box.createHorizontalStrut(10)); + } - JButton aufgeben = new JButton("Aufgeben"); - aufgeben.setBackground(Color.LIGHT_GRAY); - aufgeben.setForeground(Color.BLACK); - aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16)); - aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT); - aufgebenUndo.add(aufgeben); + aufgebenUndo.add(Box.createHorizontalStrut(10)); - // Button-Listener - aufgeben.addActionListener(new ButtonAufgebenListener()); + JButton aufgeben = new JButton("Aufgeben"); + aufgeben.setBackground(Color.LIGHT_GRAY); + aufgeben.setForeground(Color.BLACK); + aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16)); + aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT); + aufgebenUndo.add(aufgeben); - aufgebenUndo.add(Box.createHorizontalStrut(10)); + // Button-Listener + aufgeben.addActionListener(new ButtonAufgebenListener()); - JButton safe = new JButton("Spielstand sichern"); - safe.setBackground(Color.LIGHT_GRAY); - safe.setForeground(Color.BLACK); - safe.setFont(new Font("Tahoma", Font.BOLD, 16)); - safe.setAlignmentX(Component.CENTER_ALIGNMENT); - aufgebenUndo.add(safe); + aufgebenUndo.add(Box.createHorizontalStrut(10)); - // Button-Listener - safe.addActionListener(new ButtonFileSaverListener(this, this.game)); + JButton safe = new JButton("Spielstand sichern"); + safe.setBackground(Color.LIGHT_GRAY); + safe.setForeground(Color.BLACK); + safe.setFont(new Font("Tahoma", Font.BOLD, 16)); + safe.setAlignmentX(Component.CENTER_ALIGNMENT); + aufgebenUndo.add(safe); - playerOne.add(aufgebenUndo); + // Button-Listener + safe.addActionListener(new ButtonFileSaverListener(this, this.game)); - playerOne.add(Box.createVerticalStrut(15)); + playerOne.add(aufgebenUndo); - JLabel clock1 = clock.getClock1(); - playerOne.add(clock1); + playerOne.add(Box.createVerticalStrut(15)); - playerOne.add(Box.createVerticalStrut(10)); + JLabel clock1 = clock.getClock1(); + playerOne.add(clock1); - JLabel pl2 = new JLabel("Player 1:"); - pl2.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); - pl2.setFont(new Font("Calibri", Font.BOLD, 35)); - pl2.setForeground(Color.BLACK); - pl2.setAlignmentX(Component.CENTER_ALIGNMENT); - playerOne.add(pl2); + playerOne.add(Box.createVerticalStrut(10)); - return playerOne; - } + JLabel pl2 = new JLabel("Player 1:"); + pl2.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); + pl2.setFont(new Font("Calibri", Font.BOLD, 35)); + pl2.setForeground(Color.BLACK); + pl2.setAlignmentX(Component.CENTER_ALIGNMENT); + playerOne.add(pl2); - public void setBoardMode(BoardMode bm) { - this.mode = bm; - } + return playerOne; + } - public void setSelectedSquare(Square sq) { - this.selectedSquare = sq; - } + public void setBoardMode(BoardMode bm) { + this.mode = bm; + } - public HashMap getBelegung() { - return this.belegungen; - } + public void setSelectedSquare(Square sq) { + this.selectedSquare = sq; + } - public JButton getUndo() { - return undo; - } + public HashMap getBelegung() { + return this.belegungen; + } - public JButton getUndo2() { - return undo2; - } + public JButton getUndo() { + return undo; + } - public BoardMode getMode() { - return mode; - } + public JButton getUndo2() { + return undo2; + } - public Clock getClock() { - return clock; - } + public BoardMode getMode() { + return mode; + } + + public Clock getClock() { + return clock; + } }