diff --git a/src/main/java/de/mannheim/th/chess/controller/ButtonAufgebenListener.java b/src/main/java/de/mannheim/th/chess/controller/ButtonAufgebenListener.java index 0dfd08f..6365180 100644 --- a/src/main/java/de/mannheim/th/chess/controller/ButtonAufgebenListener.java +++ b/src/main/java/de/mannheim/th/chess/controller/ButtonAufgebenListener.java @@ -46,6 +46,7 @@ public class ButtonAufgebenListener extends JFrame implements ActionListener { } this.sf.setBoardMode(BoardMode.finished); + this.sf.enableControlPanelButtons(); sf.setButtonsActions(); diff --git a/src/main/java/de/mannheim/th/chess/ui/MainFrame.java b/src/main/java/de/mannheim/th/chess/ui/MainFrame.java index 0e93b36..32e389d 100644 --- a/src/main/java/de/mannheim/th/chess/ui/MainFrame.java +++ b/src/main/java/de/mannheim/th/chess/ui/MainFrame.java @@ -87,6 +87,10 @@ public class MainFrame extends JFrame { contentPane.add(Box.createVerticalStrut(15)); JButton pgnLoaderButton = new JButton("Lade aus PGN Datei"); + pgnLoaderButton.setBackground(Color.LIGHT_GRAY); + pgnLoaderButton.setForeground(Color.BLACK); + pgnLoaderButton.setFont(new Font("Tahoma", Font.BOLD, 16)); + pgnLoaderButton.setAlignmentX(CENTER_ALIGNMENT); pgnLoaderButton.addActionListener(e -> openPgnSelectFrame()); contentPane.add(pgnLoaderButton); @@ -116,7 +120,7 @@ public class MainFrame extends JFrame { */ public void startGame() { if (this.game != null) { - this.game.stopClock(); + //this.game.stopClock(); new SpielFrame(this.game); } } 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 3de9e9c..6ed6132 100644 --- a/src/main/java/de/mannheim/th/chess/ui/SpielFrame.java +++ b/src/main/java/de/mannheim/th/chess/ui/SpielFrame.java @@ -50,646 +50,667 @@ import java.awt.GridLayout; public class SpielFrame extends JFrame { - // 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, controlPanel; - private JButton undo, undo2, aufgeben, aufgeben2; - private JTextArea ausgabe; - private Game game; - private Clock clock; - private ArrayList anzeigeMoves = new ArrayList(); - private boolean wechsel = false; - - private BoardMode mode; - private Square selectedSquare; - - public enum BoardMode { - normal, pieceSelected, finished, gameEnd - } - - /** - * Create the frame. - */ - public SpielFrame(Game game) { - - this.game = game; - this.clock = game.getClock(); - this.clock.start(); - - mode = BoardMode.normal; - - setDefaultCloseOperation(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()); - - panelRechts.add(createControlPanel()); - - // 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.setDefaultButtons(); - this.setButtonsActions(); - this.applyBoardButtons(); - - this.ladeBrett(); - - } - - /** - * Sets the to default buttons - */ - public void setDefaultButtons() { - this.clearButtons(); - this.setDefaultBackground(); - } - - /** - * holt sich FEN-Zeichenkette und extrahiert daraus die Positionen der Figuren - */ - public void ladeBrett() { - 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++) { - int idx; - if (game.isRotieren()) - idx = wechsel ? mirrowedGrid(i) : i; - else - idx = i; - belegungen.put(buttons.get(idx), "n-n"); - i++; - } - continue; - } else if (fen[j] >= 65 && fen[j] <= 90) { // Großbuchstabe = weiß - int idx; - if (game.isRotieren()) - idx = wechsel ? mirrowedGrid(i) : i; - else - idx = i; - belegungen.put(buttons.get(idx), "w-" + fen[j]); - } else if (fen[j] >= 97 && fen[j] <= 122) { // Kleinbuchstabe = schwarz - int idx; - if (game.isRotieren()) - idx = wechsel ? mirrowedGrid(i) : i; - else - idx = i; - belegungen.put(buttons.get(idx), "b-" + fen[j]); - } - int idx; - if (game.isRotieren()) - idx = wechsel ? mirrowedGrid(i) : i; - else - idx = i; - buttons.get(idx).setIcon(new ImageIcon("src/main/resources/" + (int) fen[j] + ".png")); - buttons.get(idx).setDisabledIcon(new ImageIcon("src/main/resources/" + (int) fen[j] + ".png")); - i++; - } - } - - /* - * Switches the button actions depending on the boardmode - */ - public void setButtonsActions() { - - List selectables; - - switch (this.mode) { - case normal: - selectables = game.getAllLegalMoveableSquares(); - for (Square square : selectables) { - int idx; - - if (game.isRotieren()) - idx = wechsel ? square.ordinal() : mirrowedGrid(square.ordinal()); - else - idx = this.mirrowedGrid(square.ordinal()); - - JButton b = buttons.get(idx); - b.setEnabled(true); - b.addActionListener(new ButtonSelectPieceListener(this, square)); - } - break; - - case pieceSelected: - int idxSelected; - - if (game.isRotieren()) - idxSelected = wechsel ? selectedSquare.ordinal() : mirrowedGrid(selectedSquare.ordinal()); - else - idxSelected = mirrowedGrid(selectedSquare.ordinal()); - - JButton s = buttons.get(idxSelected); - s.setEnabled(true); - s.setBackground(new Color(165, 42, 42)); - s.addActionListener(new ButtonToNormalListener(this)); - - selectables = game.getLegalMoveableSquares(selectedSquare); - for (Square square : selectables) { - int idx; - if (game.isRotieren()) - idx = wechsel ? square.ordinal() : mirrowedGrid(square.ordinal()); - else - idx = mirrowedGrid(square.ordinal()); - final Move move = new Move(selectedSquare, square); - JButton b = buttons.get(idx); - b.setEnabled(true); - b.setBackground(new Color(230, 100, 100)); - b.addActionListener(new ButtonMovePieceListener(this, this.game, move)); - } - break; - - case finished: - break; - - case gameEnd: - break; - - default: - break; - } - } - - /** - * Inverts the Enabled property of the controlpanelButtons - */ - public void enableControlPanelButtons() { - for (Component c : this.controlPanel.getComponents()) { - if (c instanceof JButton) { - c.setEnabled(!c.isEnabled()); - } - } - } - - /** - * Adds the buttons to the boardpanel - */ - public void applyBoardButtons() { - for (JButton b : buttons) { - panelLinks.add(b); - } - } - - public void showWin(int player) { - JFrame frame = new JFrame("Result"); - frame.setDefaultCloseOperation(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 showResult(String res) { - - ausgabe.setFont(new Font("Calibri", Font.BOLD, 40)); - ausgabe.setForeground(new Color(178, 34, 34)); - ausgabe.setText(" " + res); - - } - - 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]; - } - - public HashMap getBelegung() { - return this.belegungen; - } - - public boolean isWechsel() { - return wechsel; - } - - public JButton getUndo() { - return undo; - } - - public JButton getUndo2() { - return undo2; - } - - public BoardMode getMode() { - return mode; - } - - public Clock getClock() { - return clock; - } - - public JButton getAufgeben() { - return aufgeben; - } - - public JButton getAufgeben2() { - return aufgeben2; - } - - public void setMode(BoardMode mode) { - this.mode = mode; - } - - public void setBoardMode(BoardMode bm) { - this.mode = bm; - } - - public void setSelectedSquare(Square sq) { - this.selectedSquare = sq; - } - - public void setAufgeben(JButton aufgeben) { - this.aufgeben = aufgeben; - } - - public void setAufgeben2(JButton aufgeben2) { - this.aufgeben2 = aufgeben2; - } - - public void setWechsel(boolean wechsel) { - this.wechsel = wechsel; - } - - private int mirrowedGrid(int i) { - return 63 - (((i / 8) * 8) + (7 - i % 8)); - } - - /** - * Creates the controlPanel and its Buttons - */ - private JPanel createControlPanel() { - this.controlPanel = new JPanel(); - this.controlPanel.setBackground(new Color(90, 90, 90)); - this.controlPanel.setLayout(new FlowLayout()); - - this.controlPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, controlPanel.getPreferredSize().height)); - - // ----- ViewQuicksaveButton ----- - JButton quicksave = new JButton("Quicksave"); - quicksave.setEnabled(true); - quicksave.addActionListener(new ButtonQuicksaveListener(this.game)); - this.controlPanel.add(quicksave); - - // ----- ViewFirstButton ----- - JButton viewFirstButton = new JButton("<<-"); - viewFirstButton.setEnabled(false); - viewFirstButton.addActionListener(new ButtonViewFirstListener(this.game, this)); - this.controlPanel.add(viewFirstButton); - - // ----- ViewBackButton ----- - JButton viewBackButton = new JButton("<-"); - viewBackButton.setEnabled(false); - viewBackButton.addActionListener(new ButtonViewBackListener(this.game, this)); - this.controlPanel.add(viewBackButton); - - // ----- ViewForwardButton ----- - JButton viewForwardButton = new JButton("->"); - viewForwardButton.setEnabled(false); - viewForwardButton.addActionListener(new ButtonViewForwardListener(this.game, this)); - this.controlPanel.add(viewForwardButton); - - // ----- ViewLastButton ----- - JButton viewLastButton = new JButton("->>"); - viewLastButton.setEnabled(false); - viewLastButton.addActionListener(new ButtonViewLastListener(this.game, this)); - this.controlPanel.add(viewLastButton); + // 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, controlPanel; + private JButton undo, undo2, aufgeben, aufgeben2; + private JTextArea ausgabe; + private Game game; + private Clock clock; + private ArrayList anzeigeMoves = new ArrayList(); + private boolean wechsel = false; + + 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(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()); + + panelRechts.add(createControlPanel()); + + // 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.setDefaultButtons(); + this.setButtonsActions(); + this.applyBoardButtons(); + + this.ladeBrett(); + + } + + /** + * Sets the to default buttons + */ + public void setDefaultButtons() { + this.clearButtons(); + this.setDefaultBackground(); + } + + /** + * holt sich FEN-Zeichenkette und extrahiert daraus die Positionen der Figuren + */ + public void ladeBrett() { + 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++) { + int idx; + if (game.isRotieren()) + idx = wechsel ? mirrowedGrid(i) : i; + else + idx = i; + belegungen.put(buttons.get(idx), "n-n"); + i++; + } + continue; + } else if (fen[j] >= 65 && fen[j] <= 90) { // Großbuchstabe = weiß + int idx; + if (game.isRotieren()) + idx = wechsel ? mirrowedGrid(i) : i; + else + idx = i; + belegungen.put(buttons.get(idx), "w-" + fen[j]); + } else if (fen[j] >= 97 && fen[j] <= 122) { // Kleinbuchstabe = schwarz + int idx; + if (game.isRotieren()) + idx = wechsel ? mirrowedGrid(i) : i; + else + idx = i; + belegungen.put(buttons.get(idx), "b-" + fen[j]); + } + int idx; + if (game.isRotieren()) + idx = wechsel ? mirrowedGrid(i) : i; + else + idx = i; + buttons.get(idx).setIcon(new ImageIcon("src/main/resources/" + (int) fen[j] + ".png")); + buttons.get(idx).setDisabledIcon(new ImageIcon("src/main/resources/" + (int) fen[j] + ".png")); + i++; + } + } + + /* + * Switches the button actions depending on the boardmode + */ + public void setButtonsActions() { + + List selectables; + + switch (this.mode) { + case normal: + selectables = game.getAllLegalMoveableSquares(); + for (Square square : selectables) { + int idx; + + if (game.isRotieren()) + idx = wechsel ? square.ordinal() : mirrowedGrid(square.ordinal()); + else + idx = this.mirrowedGrid(square.ordinal()); + + JButton b = buttons.get(idx); + b.setEnabled(true); + b.addActionListener(new ButtonSelectPieceListener(this, square)); + } + break; + + case pieceSelected: + int idxSelected; + + if (game.isRotieren()) + idxSelected = wechsel ? selectedSquare.ordinal() : mirrowedGrid(selectedSquare.ordinal()); + else + idxSelected = mirrowedGrid(selectedSquare.ordinal()); + + JButton s = buttons.get(idxSelected); + s.setEnabled(true); + s.setBackground(new Color(165, 42, 42)); + s.addActionListener(new ButtonToNormalListener(this)); + + selectables = game.getLegalMoveableSquares(selectedSquare); + for (Square square : selectables) { + int idx; + if (game.isRotieren()) + idx = wechsel ? square.ordinal() : mirrowedGrid(square.ordinal()); + else + idx = mirrowedGrid(square.ordinal()); + final Move move = new Move(selectedSquare, square); + JButton b = buttons.get(idx); + b.setEnabled(true); + b.setBackground(new Color(230, 100, 100)); + b.addActionListener(new ButtonMovePieceListener(this, this.game, move)); + } + break; + + case finished: + break; + + default: + break; + } + } + + /** + * Inverts the Enabled property of the controlpanelButtons + */ + public void enableControlPanelButtons() { + for (Component c : this.controlPanel.getComponents()) { + if (c instanceof JButton) { + c.setEnabled(!c.isEnabled()); + } + } + } + + /** + * Adds the buttons to the boardpanel + */ + public void applyBoardButtons() { + for (JButton b : buttons) { + panelLinks.add(b); + } + } + + public void showWin(int player) { + JFrame frame = new JFrame("Result"); + frame.setDefaultCloseOperation(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 showResult(String res) { + + ausgabe.setFont(new Font("Calibri", Font.BOLD, 40)); + ausgabe.setForeground(new Color(178, 34, 34)); + ausgabe.setText(" " + res); + + } + + 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]; + } + + public HashMap getBelegung() { + return this.belegungen; + } + + public boolean isWechsel() { + return wechsel; + } + + public JButton getUndo() { + return undo; + } + + public JButton getUndo2() { + return undo2; + } + + public BoardMode getMode() { + return mode; + } + + public Clock getClock() { + return clock; + } + + public JButton getAufgeben() { + return aufgeben; + } + + public JButton getAufgeben2() { + return aufgeben2; + } + + public void setMode(BoardMode mode) { + this.mode = mode; + } + + public void setBoardMode(BoardMode bm) { + this.mode = bm; + } + + public void setSelectedSquare(Square sq) { + this.selectedSquare = sq; + } + + public void setAufgeben(JButton aufgeben) { + this.aufgeben = aufgeben; + } + + public void setAufgeben2(JButton aufgeben2) { + this.aufgeben2 = aufgeben2; + } + + public void setWechsel(boolean wechsel) { + this.wechsel = wechsel; + } + + private int mirrowedGrid(int i) { + return 63 - (((i / 8) * 8) + (7 - i % 8)); + } + + /** + * Creates the controlPanel and its Buttons + */ + private JPanel createControlPanel() { + this.controlPanel = new JPanel(); + this.controlPanel.setBackground(new Color(90, 90, 90)); + this.controlPanel.setLayout(new FlowLayout()); + + this.controlPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, controlPanel.getPreferredSize().height)); + + // ----- ViewQuicksaveButton ----- + JButton quicksave = new JButton("Quicksave"); + quicksave.setBackground(Color.LIGHT_GRAY); + quicksave.setForeground(Color.BLACK); + quicksave.setFont(new Font("Tahoma", Font.BOLD, 16)); + quicksave.setAlignmentX(CENTER_ALIGNMENT); + quicksave.setEnabled(true); + quicksave.addActionListener(new ButtonQuicksaveListener(this.game)); + this.controlPanel.add(quicksave); + + // ----- ViewFirstButton ----- + JButton viewFirstButton = new JButton("<<-"); + viewFirstButton.setBackground(Color.LIGHT_GRAY); + viewFirstButton.setForeground(Color.BLACK); + viewFirstButton.setFont(new Font("Tahoma", Font.BOLD, 16)); + viewFirstButton.setAlignmentX(CENTER_ALIGNMENT); + viewFirstButton.setEnabled(false); + viewFirstButton.addActionListener(new ButtonViewFirstListener(this.game, this)); + this.controlPanel.add(viewFirstButton); + + // ----- ViewBackButton ----- + JButton viewBackButton = new JButton("<-"); + viewBackButton.setBackground(Color.LIGHT_GRAY); + viewBackButton.setForeground(Color.BLACK); + viewBackButton.setFont(new Font("Tahoma", Font.BOLD, 16)); + viewBackButton.setAlignmentX(CENTER_ALIGNMENT); + viewBackButton.setEnabled(false); + viewBackButton.addActionListener(new ButtonViewBackListener(this.game, this)); + this.controlPanel.add(viewBackButton); + + // ----- ViewForwardButton ----- + JButton viewForwardButton = new JButton("->"); + viewForwardButton.setBackground(Color.LIGHT_GRAY); + viewForwardButton.setForeground(Color.BLACK); + viewForwardButton.setFont(new Font("Tahoma", Font.BOLD, 16)); + viewForwardButton.setAlignmentX(CENTER_ALIGNMENT); + viewForwardButton.setEnabled(false); + viewForwardButton.addActionListener(new ButtonViewForwardListener(this.game, this)); + this.controlPanel.add(viewForwardButton); + + // ----- ViewLastButton ----- + JButton viewLastButton = new JButton("->>"); + viewLastButton.setBackground(Color.LIGHT_GRAY); + viewLastButton.setForeground(Color.BLACK); + viewLastButton.setFont(new Font("Tahoma", Font.BOLD, 16)); + viewLastButton.setAlignmentX(CENTER_ALIGNMENT); + viewLastButton.setEnabled(false); + viewLastButton.addActionListener(new ButtonViewLastListener(this.game, this)); + this.controlPanel.add(viewLastButton); + + // ----- ViewQuickloadButton ----- + JButton quickload = new JButton("Quickload"); + quickload.setBackground(Color.LIGHT_GRAY); + quickload.setForeground(Color.BLACK); + quickload.setFont(new Font("Tahoma", Font.BOLD, 16)); + quickload.setAlignmentX(CENTER_ALIGNMENT); + quickload.setEnabled(true); + quickload.addActionListener(new ButtonQuickloadListener(this.game, this)); + this.controlPanel.add(quickload); + + return controlPanel; + } + + 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(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(CENTER_ALIGNMENT); + aufgebenUndo.add(undo); + + // Button-Listener + undo.addActionListener(new ButtonUndoMoveListener(this, this.game)); + } + + aufgebenUndo.add(Box.createHorizontalStrut(10)); + + aufgeben2 = new JButton("Aufgeben"); + aufgeben2.setBackground(Color.LIGHT_GRAY); + aufgeben2.setForeground(Color.BLACK); + aufgeben2.setFont(new Font("Tahoma", Font.BOLD, 16)); + aufgeben2.setAlignmentX(CENTER_ALIGNMENT); + + aufgeben2.addActionListener(new ButtonAufgebenListener(this, this.game)); + aufgebenUndo.add(aufgeben2); + + 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(CENTER_ALIGNMENT); + aufgebenUndo.add(safe); + + // Button-Listener + safe.addActionListener(new ButtonFileSaverListener(this, this.game)); - // ----- ViewQuickloadButton ----- - JButton quickload = new JButton("Quickload"); - quickload.setEnabled(true); - quickload.addActionListener(new ButtonQuickloadListener(this.game, this)); - this.controlPanel.add(quickload); + playerTwo.add(aufgebenUndo); - return controlPanel; - } + playerTwo.add(Box.createVerticalStrut(10)); - private JPanel getUiPlayerTwo() { + return playerTwo; + } - JPanel playerTwo = new JPanel(); - playerTwo.setBackground(new Color(90, 90, 90)); - playerTwo.setLayout(new BoxLayout(playerTwo, BoxLayout.Y_AXIS)); + private JPanel getUiStatistik() { - playerTwo.add(Box.createVerticalStrut(15)); + JPanel statistik = new JPanel(); + statistik.setBackground(new Color(90, 90, 90)); + statistik.setLayout(new BoxLayout(statistik, BoxLayout.Y_AXIS)); - 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(CENTER_ALIGNMENT); - playerTwo.add(pl2); + 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"); - playerTwo.add(Box.createVerticalStrut(10)); + JScrollPane scrollPane = new JScrollPane(ausgabe); + scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - JLabel clock1 = clock.getClock2(); - playerTwo.add(clock1); + statistik.add(scrollPane); - playerTwo.add(Box.createVerticalStrut(10)); + return statistik; + } - // 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)); + public void aktualisiereAusgabe() { - 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(CENTER_ALIGNMENT); - aufgebenUndo.add(undo); + StringBuilder sb = new StringBuilder(); + sb.append("\n Bisherige Züge:\n"); - // Button-Listener - undo.addActionListener(new ButtonUndoMoveListener(this, this.game)); - } + MoveList l = game.getMoveList(); + anzeigeMoves.add(" " + game.getUnicodeFromMove(l.getLast()) + ": " + l.getLast().toString() + "\n"); - aufgebenUndo.add(Box.createHorizontalStrut(10)); + for (String line : anzeigeMoves) { + sb.append(line); + } - aufgeben2 = new JButton("Aufgeben"); - aufgeben2.setBackground(Color.LIGHT_GRAY); - aufgeben2.setForeground(Color.BLACK); - aufgeben2.setFont(new Font("Tahoma", Font.BOLD, 16)); - aufgeben2.setAlignmentX(CENTER_ALIGNMENT); + ausgabe.setText(sb.toString()); + } - aufgeben2.addActionListener(new ButtonAufgebenListener(this, this.game)); - aufgebenUndo.add(aufgeben2); + public void deleteLastAusgabe() { + String[] zeilen = ausgabe.getText().split("\n"); - aufgebenUndo.add(Box.createHorizontalStrut(10)); + // es müssen immer mind 5 Zeilen existieren, dass also 1 Zug löschbar ist + if (zeilen.length <= 2) + return; - 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(CENTER_ALIGNMENT); - aufgebenUndo.add(safe); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < zeilen.length - 1; i++) { + sb.append(zeilen[i]).append("\n"); + } - // Button-Listener - safe.addActionListener(new ButtonFileSaverListener(this, this.game)); + ausgabe.setText(sb.toString()); + } - playerTwo.add(aufgebenUndo); + private JPanel getUiPlayerOne() { - playerTwo.add(Box.createVerticalStrut(10)); + JPanel playerOne = new JPanel(); + playerOne.setBackground(new Color(90, 90, 90)); + playerOne.setLayout(new BoxLayout(playerOne, BoxLayout.Y_AXIS)); - return playerTwo; - } + playerOne.add(Box.createVerticalStrut(10)); - private JPanel getUiStatistik() { + // 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)); - JPanel statistik = new JPanel(); - statistik.setBackground(new Color(90, 90, 90)); - statistik.setLayout(new BoxLayout(statistik, BoxLayout.Y_AXIS)); + 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(CENTER_ALIGNMENT); + aufgebenUndo.add(undo2); - 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"); + // Button-Listener + undo2.addActionListener(new ButtonUndoMoveListener(this, this.game)); - JScrollPane scrollPane = new JScrollPane(ausgabe); - scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + } - statistik.add(scrollPane); + aufgebenUndo.add(Box.createHorizontalStrut(10)); - return statistik; - } + aufgeben = new JButton("Aufgeben"); + aufgeben.setBackground(Color.LIGHT_GRAY); + aufgeben.setForeground(Color.BLACK); + aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16)); + aufgeben.setAlignmentX(CENTER_ALIGNMENT); + aufgeben.addActionListener(new ButtonAufgebenListener(this, this.game)); - public void aktualisiereAusgabe() { + aufgebenUndo.add(aufgeben); - StringBuilder sb = new StringBuilder(); - sb.append("\n Bisherige Züge:\n"); + aufgebenUndo.add(Box.createHorizontalStrut(10)); - MoveList l = game.getMoveList(); - anzeigeMoves.add(" " + game.getUnicodeFromMove(l.getLast()) + ": " + l.getLast().toString() + "\n"); + 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(CENTER_ALIGNMENT); + aufgebenUndo.add(safe); - for (String line : anzeigeMoves) { - sb.append(line); - } + // Button-Listener + safe.addActionListener(new ButtonFileSaverListener(this, this.game)); - ausgabe.setText(sb.toString()); - } + playerOne.add(aufgebenUndo); - public void deleteLastAusgabe() { - String[] zeilen = ausgabe.getText().split("\n"); + playerOne.add(Box.createVerticalStrut(15)); - // es müssen immer mind 5 Zeilen existieren, dass also 1 Zug löschbar ist - if (zeilen.length <= 2) - return; + JLabel clock1 = clock.getClock1(); + playerOne.add(clock1); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < zeilen.length - 1; i++) { - sb.append(zeilen[i]).append("\n"); - } + playerOne.add(Box.createVerticalStrut(10)); - ausgabe.setText(sb.toString()); - } + 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(CENTER_ALIGNMENT); + playerOne.add(pl2); - private JPanel getUiPlayerOne() { + return playerOne; + } - JPanel playerOne = new JPanel(); - playerOne.setBackground(new Color(90, 90, 90)); - playerOne.setLayout(new BoxLayout(playerOne, BoxLayout.Y_AXIS)); + /** + * Sets the default background color for the buttons in the grid. + */ + private void setDefaultBackground() { + int counter = 8; + 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)); - playerOne.add(Box.createVerticalStrut(10)); + } else { + // logger.info("Dunkles Feld erstellt." + i); + b.setBackground(new Color(65, 65, 65)); + } - // 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)); + if (i % 8 == 0) { + b.setHorizontalAlignment(SwingConstants.CENTER); + b.setVerticalAlignment(SwingConstants.CENTER); - 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(CENTER_ALIGNMENT); - aufgebenUndo.add(undo2); + b.setHorizontalTextPosition(SwingConstants.LEFT); // Text rechts vom Icon + b.setVerticalTextPosition(SwingConstants.BOTTOM); - // Button-Listener - undo2.addActionListener(new ButtonUndoMoveListener(this, this.game)); + b.setIconTextGap(5); - } + b.setText(String.valueOf(counter) + b.getText()); + counter--; + } + } - aufgebenUndo.add(Box.createHorizontalStrut(10)); + char buchstabe = 'a'; + for (int j = 0; j < 8; j++) { + JButton button = buttons.get(mirrowedGrid(j)); - aufgeben = new JButton("Aufgeben"); - aufgeben.setBackground(Color.LIGHT_GRAY); - aufgeben.setForeground(Color.BLACK); - aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16)); - aufgeben.setAlignmentX(CENTER_ALIGNMENT); - aufgeben.addActionListener(new ButtonAufgebenListener(this, this.game)); + button.setHorizontalAlignment(SwingConstants.CENTER); + button.setVerticalAlignment(SwingConstants.CENTER); - aufgebenUndo.add(aufgeben); + button.setHorizontalTextPosition(SwingConstants.RIGHT); // Text rechts vom Icon + button.setVerticalTextPosition(SwingConstants.BOTTOM); - aufgebenUndo.add(Box.createHorizontalStrut(10)); + button.setIconTextGap(5); - 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(CENTER_ALIGNMENT); - aufgebenUndo.add(safe); + button.setText(String.valueOf(buchstabe)); + buchstabe++; + } - // Button-Listener - safe.addActionListener(new ButtonFileSaverListener(this, this.game)); + } - playerOne.add(aufgebenUndo); + /** + * Clears the existing buttons from the button list, panellinks and fills them + * with new blank ones. + */ + private void clearButtons() { - playerOne.add(Box.createVerticalStrut(15)); + buttons.clear(); + panelLinks.removeAll(); - JLabel clock1 = clock.getClock1(); - playerOne.add(clock1); + for (int i = 0; i < 64; i++) { + JButton b = new JButton(); - playerOne.add(Box.createVerticalStrut(10)); + b.setEnabled(false); - 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(CENTER_ALIGNMENT); - playerOne.add(pl2); + // 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 + ""); - return playerOne; - } - - /** - * Sets the default background color for the buttons in the grid. - */ - private void setDefaultBackground() { - int counter = 8; - 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)); - } - - if (i % 8 == 0) { - b.setHorizontalAlignment(SwingConstants.CENTER); - b.setVerticalAlignment(SwingConstants.CENTER); - - b.setHorizontalTextPosition(SwingConstants.LEFT); // Text rechts vom Icon - b.setVerticalTextPosition(SwingConstants.BOTTOM); - - b.setIconTextGap(5); - - b.setText(String.valueOf(counter) + b.getText()); - counter--; - } - } - - char buchstabe = 'a'; - for (int j = 0; j < 8; j++) { - JButton button = buttons.get(mirrowedGrid(j)); - - button.setHorizontalAlignment(SwingConstants.CENTER); - button.setVerticalAlignment(SwingConstants.CENTER); - - button.setHorizontalTextPosition(SwingConstants.RIGHT); // Text rechts vom Icon - button.setVerticalTextPosition(SwingConstants.BOTTOM); - - button.setIconTextGap(5); - - button.setText(String.valueOf(buchstabe)); - buchstabe++; - } - - } - - /** - * 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); - } - } + buttons.add(b); + } + } }