add controlpanel

pgnReader
dstuck 2025-06-24 17:45:14 +02:00
parent 596a3a4dea
commit 039a5756ee
7 changed files with 595 additions and 442 deletions

View File

@ -30,19 +30,23 @@ public class ButtonMovePieceListener implements ActionListener {
if (this.game.isDraw()) { if (this.game.isDraw()) {
this.game.stopClock(); this.game.stopClock();
this.sf.setBoardMode(BoardMode.finished); this.sf.setBoardMode(BoardMode.finished);
this.sf.setViewPointer(this.game.getMoveList().size() - 1);
this.sf.showDraw(); this.sf.showDraw();
} else if (this.game.isMate()) { } else if (this.game.isMate()) {
this.game.stopClock(); this.game.stopClock();
this.sf.setBoardMode(BoardMode.finished); this.sf.setBoardMode(BoardMode.finished);
this.sf.setViewPointer(this.game.getMoveList().size() - 1);
this.sf.showWin(game.getActivePlayer()); this.sf.showWin(game.getActivePlayer());
} else {
this.sf.setBoardMode(BoardMode.normal);
} }
this.sf.setBoardMode(BoardMode.normal);
this.sf.setCursor(null); this.sf.setCursor(null);
this.sf.erstelleBrett(); this.sf.erstelleBrett();
if (game.getLastMove() != null) { if (game.getLastMove() != null) {
sf.aktualisiereAusgabe(); sf.aktualisiereAusgabe();
} }
} }
} }

View File

@ -0,0 +1,22 @@
package de.mannheim.th.chess.controller.controlPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import de.mannheim.th.chess.domain.Game;
public class ButtonViewBackListener implements ActionListener {
private Game game;
public ButtonViewBackListener(Game game) {
this.game = game;
}
@Override
public void actionPerformed(ActionEvent e) {
this.game.setViewPointer(this.game.getViewPointer() - 1);
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,22 @@
package de.mannheim.th.chess.controller.controlPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import de.mannheim.th.chess.domain.Game;
public class ButtonViewFirstListener implements ActionListener {
private Game game;
public ButtonViewFirstListener(Game game) {
this.game = game;
}
@Override
public void actionPerformed(ActionEvent e) {
this.game.setViewPointer(0);
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,22 @@
package de.mannheim.th.chess.controller.controlPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import de.mannheim.th.chess.domain.Game;
public class ButtonViewForwardListener implements ActionListener {
private Game game;
public ButtonViewForwardListener(Game game) {
this.game = game;
}
@Override
public void actionPerformed(ActionEvent e) {
this.game.setViewPointer(this.game.getViewPointer() + 1);
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,23 @@
package de.mannheim.th.chess.controller.controlPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import de.mannheim.th.chess.domain.Game;
public class ButtonViewLastListener implements ActionListener {
private Game game;
public ButtonViewLastListener(Game game) {
this.game = game;
}
@Override
public void actionPerformed(ActionEvent e) {
this.game.setViewPointer(this.game.getMoveList().size() - 1);
// TODO Auto-generated method stub
}
}

View File

@ -34,6 +34,7 @@ public class Game {
private boolean rotieren, zuruecknahme; private boolean rotieren, zuruecknahme;
private MoveList movelist; private MoveList movelist;
private int viewPointer;
public Game() { public Game() {
@ -272,11 +273,23 @@ public class Game {
return board.getFen(); return board.getFen();
} }
// public Square getSelectedSquare() { // public Square getSelectedSquare() {
// return this.getSelectedSquare(); // return this.getSelectedSquare();
// } // }
public String getUnicodeFromMove(Move move) { public String getUnicodeFromMove(Move move) {
return board.getPiece(move.getTo()).getFanSymbol().toUpperCase(); return board.getPiece(move.getTo()).getFanSymbol().toUpperCase();
} }
public void setViewPointer(int i) {
this.viewPointer = i;
}
public int getViewPointer() {
return this.viewPointer;
}
public void loadView() {
// TODO: add functionality
}
} }

View File

@ -36,7 +36,8 @@ import javax.swing.JTextArea;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -44,492 +45,538 @@ import java.awt.GridLayout;
public class SpielFrame extends JFrame { 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 static final long serialVersionUID = 1L;
private ArrayList<JButton> buttons = new ArrayList<>(); private ArrayList<JButton> buttons = new ArrayList<>();
private HashMap<JButton, String> belegungen = new HashMap<>(); private HashMap<JButton, String> belegungen = new HashMap<>();
private JPanel panelLinks, panelRechts, contentPane; private JPanel panelLinks, panelRechts, contentPane, controlPanel;
private JButton undo, undo2; private JButton undo, undo2;
private JTextArea ausgabe; private JTextArea ausgabe;
private Game game; private Game game;
private Clock clock; private Clock clock;
private ArrayList<String> anzeigeMoves = new ArrayList<String>(); private ArrayList<String> anzeigeMoves = new ArrayList<String>();
private BoardMode mode; private BoardMode mode;
private Square selectedSquare; private Square selectedSquare;
public enum BoardMode { private int viewPointer;
normal, pieceSelected, finished
} public enum BoardMode {
normal, pieceSelected, finished
/** }
* Create the frame.
*/ /**
public SpielFrame(Game game) { * Create the frame.
*/
this.game = game; public SpielFrame(Game game) {
this.clock = game.getClock();
this.clock.start(); this.game = game;
this.clock = game.getClock();
mode = BoardMode.normal; this.clock.start();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); mode = BoardMode.normal;
setBounds(100, 100, 1920, 1080);
setTitle("Schach"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true); setBounds(100, 100, 1920, 1080);
setTitle("Schach");
contentPane = new JPanel(); setAlwaysOnTop(true);
contentPane.setLayout(new BorderLayout());
setContentPane(contentPane); contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
// Linkes Panel mit GridLayout 8x8 für Schachbrett setContentPane(contentPane);
panelLinks = new JPanel(new GridLayout(8, 8));
// Linkes Panel mit GridLayout 8x8 für Schachbrett
erstelleBrett(); panelLinks = new JPanel(new GridLayout(8, 8));
// Rechtes Panel für Steuerung oder zusätzliche Eingaben erstelleBrett();
panelRechts = new JPanel();
panelRechts.setBackground(new Color(90, 90, 90)); // Rechtes Panel für Steuerung oder zusätzliche Eingaben
panelRechts.setLayout(new BoxLayout(panelRechts, BoxLayout.Y_AXIS)); panelRechts = new JPanel();
panelRechts.setBackground(new Color(90, 90, 90));
// Panel für alle Eingaben von Player 2 panelRechts.setLayout(new BoxLayout(panelRechts, BoxLayout.Y_AXIS));
panelRechts.add(getUiPlayerTwo());
// Panel für alle Eingaben von Player 2
// Panel für Statistikanzeigen panelRechts.add(getUiPlayerTwo());
panelRechts.add(getUiStatistik());
panelRechts.add(createControlPanel());
// Panel für alle Eingaben von Player 1
panelRechts.add(getUiPlayerOne()); // Panel für Statistikanzeigen
panelRechts.add(getUiStatistik());
// JSplitPane horizontal (linke und rechte Hälfte)
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panelLinks, panelRechts); // Panel für alle Eingaben von Player 1
splitPane.setResizeWeight(0.75); panelRechts.add(getUiPlayerOne());
splitPane.setBackground(Color.BLACK);
splitPane.setDividerSize(1); // JSplitPane horizontal (linke und rechte Hälfte)
splitPane.setEnabled(false); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panelLinks, panelRechts);
splitPane.setResizeWeight(0.75);
contentPane.add(splitPane, BorderLayout.CENTER); splitPane.setBackground(Color.BLACK);
splitPane.setDividerSize(1);
setVisible(true); splitPane.setEnabled(false);
}
contentPane.add(splitPane, BorderLayout.CENTER);
/**
* Erstellt alle Buttons und fügt sie dem Frame hinzu. setVisible(true);
*/ }
public void erstelleBrett() {
/**
this.clearButtons(); * Erstellt alle Buttons und fügt sie dem Frame hinzu.
this.setDefaultBackground(); */
this.setButtonsActions(); public void erstelleBrett() {
ladeBrett(); this.clearButtons();
this.setDefaultBackground();
panelLinks.revalidate(); this.setButtonsActions();
panelLinks.repaint();
this.ladeBrett();
}
panelLinks.revalidate();
private int mirrowedGrid(int i) { panelLinks.repaint();
return 63 - (((i / 8) * 8) + (7 - i % 8));
} }
/** private int mirrowedGrid(int i) {
* holt sich FEN-Zeichenkette und extrahiert daraus die Positionen der Figuren return 63 - (((i / 8) * 8) + (7 - i % 8));
*/ }
private void ladeBrett() {
// System.out.println(game.toFEN()); /**
* holt sich FEN-Zeichenkette und extrahiert daraus die Positionen der Figuren
char[] fen = game.toFEN().replaceAll("/", "").split(" ")[0].toCharArray(); */
int i = 0; private void ladeBrett() {
for (int j = 0; j < fen.length; j++) { // System.out.println(game.toFEN());
if (Character.isDigit(fen[j])) {
int leerfelder = Character.getNumericValue(fen[j]); char[] fen = game.toFEN().replaceAll("/", "").split(" ")[0].toCharArray();
for (int k = 0; k < leerfelder; k++) { int i = 0;
belegungen.put(buttons.get(i), "n-n"); for (int j = 0; j < fen.length; j++) {
// buttons.get(i).setEnabled(false); // erstmal deaktivieren, weil leere Felder if (Character.isDigit(fen[j])) {
// nicht ckickbar sein sollten. int leerfelder = Character.getNumericValue(fen[j]);
i++; for (int k = 0; k < leerfelder; k++) {
} belegungen.put(buttons.get(i), "n-n");
continue; // buttons.get(i).setEnabled(false); // erstmal deaktivieren, weil leere Felder
} else if (fen[j] >= 65 && fen[j] <= 90) { // ein Großbuchstabe, also // nicht ckickbar sein sollten.
belegungen.put(buttons.get(i), "w-" + fen[j]); i++;
} else if (fen[j] >= 97 && fen[j] <= 122) { // ein Kleinbuchstabe, also }
belegungen.put(buttons.get(i), "b-" + fen[j]); continue;
// buttons.get(i).setEnabled(false); // erstmal deaktivieren, damit weiß } else if (fen[j] >= 65 && fen[j] <= 90) { // ein Großbuchstabe, also
// beginnen kann belegungen.put(buttons.get(i), "w-" + fen[j]);
} } else if (fen[j] >= 97 && fen[j] <= 122) { // ein Kleinbuchstabe, also
buttons.get(i).setIcon(new ImageIcon("src/main/resources/" + (int) fen[j] + ".png")); belegungen.put(buttons.get(i), "b-" + fen[j]);
buttons.get(i).setDisabledIcon(new ImageIcon("src/main/resources/" + (int) fen[j] + ".png")); // buttons.get(i).setEnabled(false); // erstmal deaktivieren, damit weiß
// beginnen kann
i++; }
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() { /**
* Clears the existing buttons from the button list, panellinks and fills them
buttons.clear(); * with new blank ones.
panelLinks.removeAll(); */
private void clearButtons() {
for (int i = 0; i < 64; i++) {
JButton b = new JButton(); buttons.clear();
panelLinks.removeAll();
b.setEnabled(false);
for (int i = 0; i < 64; i++) {
// style JButton b = new JButton();
b.setFocusPainted(false);
b.setFont(new Font("Arial", Font.PLAIN, 30)); b.setEnabled(false);
b.setForeground(Color.WHITE);
b.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); // style
b.setName(i + ""); b.setFocusPainted(false);
b.setFont(new Font("Arial", Font.PLAIN, 30));
buttons.add(b); 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); * Sets the default background color for the buttons in the grid.
if ((i / 8 + i % 8) % 2 == 0) { */
// logger.info("Helles Feld erstellt." + i); private void setDefaultBackground() {
b.setBackground(new Color(90, 90, 90)); for (int i = 0; i < 64; i++) {
} else { JButton b = buttons.get(i);
// logger.info("Dunkles Feld erstellt." + i); if ((i / 8 + i % 8) % 2 == 0) {
b.setBackground(new Color(65, 65, 65)); // 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<Square> selectables; * Switches the button actions depending on the boardmode
*/
switch (this.mode) { private void setButtonsActions() {
case BoardMode.normal:
List<Square> selectables;
selectables = game.getAllLegalMoveableSquares();
switch (this.mode) {
for (Square square : selectables) { case BoardMode.normal:
JButton b = buttons.get(mirrowedGrid(square.ordinal()));
b.setEnabled(true); selectables = game.getAllLegalMoveableSquares();
// b.setBackground(Color.green);
b.addActionListener(new ButtonSelectPieceListener(this, square)); for (Square square : selectables) {
} JButton b = buttons.get(mirrowedGrid(square.ordinal()));
b.setEnabled(true);
break; // b.setBackground(Color.green);
b.addActionListener(new ButtonSelectPieceListener(this, square));
case BoardMode.pieceSelected: }
JButton s = buttons.get(mirrowedGrid(selectedSquare.ordinal())); break;
s.setEnabled(true);
s.setBackground(new Color(165, 42, 42)); case BoardMode.pieceSelected:
s.addActionListener(new ButtonToNormalListener(this));
JButton s = buttons.get(mirrowedGrid(selectedSquare.ordinal()));
selectables = game.getLegalMoveableSquares(selectedSquare); s.setEnabled(true);
s.setBackground(new Color(165, 42, 42));
for (Square square : selectables) { s.addActionListener(new ButtonToNormalListener(this));
JButton b = buttons.get(mirrowedGrid(square.ordinal()));
final Move move = new Move(selectedSquare, square); selectables = game.getLegalMoveableSquares(selectedSquare);
b.setEnabled(true);
b.setBackground(new Color(230, 100, 100)); for (Square square : selectables) {
b.addActionListener(new ButtonMovePieceListener(this, this.game, move)); JButton b = buttons.get(mirrowedGrid(square.ordinal()));
} final Move move = new Move(selectedSquare, square);
break; b.setEnabled(true);
case finished: b.setBackground(new Color(230, 100, 100));
clearButtons(); b.addActionListener(new ButtonMovePieceListener(this, this.game, move));
break; }
default: break;
break; case finished:
// this.enableControlPanelButtons();
} // this.viewPointer = this.game.getMoveList().size() - 1;
break;
for (JButton b : buttons) { default:
panelLinks.add(b); break;
}
} }
public void showDraw() { for (JButton b : buttons) {
JFrame frame = new JFrame("Result"); panelLinks.add(b);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
frame.setSize(300, 150); }
frame.setLayout(null);
public void showDraw() {
// JLabel jl = new JLabel(String.format("%d - %d", player / 2, player % 2)); JFrame frame = new JFrame("Result");
// jl.setBounds(50, 30, 200, 25); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// jl.setFont(new Font("Tahoma", Font.BOLD, 20)); frame.setSize(300, 150);
// frame.add(jl); frame.setLayout(null);
// frame.setVisible(true);
} // JLabel jl = new JLabel(String.format("%d - %d", player / 2, player % 2));
// jl.setBounds(50, 30, 200, 25);
public void showWin(int player) { // jl.setFont(new Font("Tahoma", Font.BOLD, 20));
JFrame frame = new JFrame("Result"); // frame.add(jl);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // frame.setVisible(true);
frame.setSize(300, 150); }
frame.setLayout(null);
public void showWin(int player) {
JLabel jl = new JLabel(String.format("%d - %d", player / 2, player % 2)); JFrame frame = new JFrame("Result");
jl.setBounds(50, 30, 200, 25); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jl.setFont(new Font("Tahoma", Font.BOLD, 20)); frame.setSize(300, 150);
frame.add(jl); frame.setLayout(null);
frame.setVisible(true);
} JLabel jl = new JLabel(String.format("%d - %d", player / 2, player % 2));
jl.setBounds(50, 30, 200, 25);
public int showPromotion() { jl.setFont(new Font("Tahoma", Font.BOLD, 20));
final int[] result = { -1 }; frame.add(jl);
frame.setVisible(true);
JDialog dialog = new JDialog(this, "Wähle eine Figur", true); }
dialog.setLayout(new GridLayout(2, 2));
dialog.setSize(300, 200); public int showPromotion() {
final int[] result = { -1 };
int[] pictures = { 81, 82, 66, 78, 113, 114, 98, 110 };
JDialog dialog = new JDialog(this, "Wähle eine Figur", true);
for (int i = 0; i < 4; i++) { dialog.setLayout(new GridLayout(2, 2));
int index = (game.getActivePlayer() - 1) * 4 + i; dialog.setSize(300, 200);
JButton jb = new JButton();
jb.setIcon(new ImageIcon("src/main/resources/" + pictures[index] + ".png")); int[] pictures = { 81, 82, 66, 78, 113, 114, 98, 110 };
int selectedPiece = index;
jb.addActionListener(e -> { for (int i = 0; i < 4; i++) {
System.out.println("Test"); int index = (game.getActivePlayer() - 1) * 4 + i;
result[0] = selectedPiece; JButton jb = new JButton();
dialog.dispose(); jb.setIcon(new ImageIcon("src/main/resources/" + pictures[index] + ".png"));
}); int selectedPiece = index;
dialog.add(jb); jb.addActionListener(e -> {
} System.out.println("Test");
result[0] = selectedPiece;
dialog.setLocationRelativeTo(null); dialog.dispose();
dialog.setVisible(true); });
dialog.add(jb);
return result[0]; }
}
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
return result[0];
}
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));
JButton viewFirstButton = new JButton("<<-");
JButton viewBackButton = new JButton("<-");
JButton viewForwardButton = new JButton("->");
JButton viewLastButton = new JButton("->>");
viewFirstButton.setEnabled(false);
viewBackButton.setEnabled(false);
viewForwardButton.setEnabled(false);
viewLastButton.setEnabled(false);
this.controlPanel.add(viewFirstButton);
this.controlPanel.add(viewBackButton);
this.controlPanel.add(viewForwardButton);
this.controlPanel.add(viewLastButton);
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(Component.CENTER_ALIGNMENT);
playerTwo.add(pl2);
private JPanel getUiPlayerTwo() { playerTwo.add(Box.createVerticalStrut(10));
JPanel playerTwo = new JPanel(); JLabel clock1 = clock.getClock2();
playerTwo.setBackground(new Color(90, 90, 90)); playerTwo.add(clock1);
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 playerTwo.add(Box.createVerticalStrut(10));
undo.addActionListener(new ButtonUndoMoveListener(this, this.game));
}
aufgebenUndo.add(Box.createHorizontalStrut(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));
JButton aufgeben = new JButton("Aufgeben"); if (game.isZuruecknahme()) {
aufgeben.setBackground(Color.LIGHT_GRAY); undo = new JButton("Zug zurücknehmen");
aufgeben.setForeground(Color.BLACK); undo.setBackground(Color.LIGHT_GRAY);
aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16)); undo.setForeground(Color.BLACK);
aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT); undo.setFont(new Font("Tahoma", Font.BOLD, 16));
aufgebenUndo.add(aufgeben); undo.setAlignmentX(Component.CENTER_ALIGNMENT);
aufgebenUndo.add(undo);
// Button-Listener // Button-Listener
aufgeben.addActionListener(new ButtonAufgebenListener()); undo.addActionListener(new ButtonUndoMoveListener(this, this.game));
}
aufgebenUndo.add(Box.createHorizontalStrut(10)); aufgebenUndo.add(Box.createHorizontalStrut(10));
JButton safe = new JButton("Spielstand sichern"); JButton aufgeben = new JButton("Aufgeben");
safe.setBackground(Color.LIGHT_GRAY); aufgeben.setBackground(Color.LIGHT_GRAY);
safe.setForeground(Color.BLACK); aufgeben.setForeground(Color.BLACK);
safe.setFont(new Font("Tahoma", Font.BOLD, 16)); aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16));
safe.setAlignmentX(Component.CENTER_ALIGNMENT); aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT);
aufgebenUndo.add(safe); aufgebenUndo.add(aufgeben);
// Button-Listener // Button-Listener
safe.addActionListener(new ButtonFileSaverListener(this, this.game)); aufgeben.addActionListener(new ButtonAufgebenListener());
playerTwo.add(aufgebenUndo); aufgebenUndo.add(Box.createHorizontalStrut(10));
playerTwo.add(Box.createVerticalStrut(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);
return playerTwo; // Button-Listener
} safe.addActionListener(new ButtonFileSaverListener(this, this.game));
private JPanel getUiStatistik() { playerTwo.add(aufgebenUndo);
JPanel statistik = new JPanel(); playerTwo.add(Box.createVerticalStrut(10));
statistik.setBackground(new Color(90, 90, 90));
statistik.setLayout(new BoxLayout(statistik, BoxLayout.Y_AXIS));
ausgabe = new JTextArea(); return playerTwo;
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); private JPanel getUiStatistik() {
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
statistik.add(scrollPane); JPanel statistik = new JPanel();
statistik.setBackground(new Color(90, 90, 90));
statistik.setLayout(new BoxLayout(statistik, BoxLayout.Y_AXIS));
return statistik; 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");
public void aktualisiereAusgabe() { JScrollPane scrollPane = new JScrollPane(ausgabe);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
StringBuilder sb = new StringBuilder(); statistik.add(scrollPane);
sb.append("\n Bisherige Züge:\n");
MoveList l = game.getMoveList(); return statistik;
anzeigeMoves.add(" " + game.getUnicodeFromMove(l.getLast()) + ": " + l.getLast().toString() + "\n"); }
for (String line : anzeigeMoves) { public void aktualisiereAusgabe() {
sb.append(line);
}
ausgabe.setText(sb.toString()); StringBuilder sb = new StringBuilder();
} sb.append("\n Bisherige Züge:\n");
public void deleteLastAusgabe() { MoveList l = game.getMoveList();
String[] zeilen = ausgabe.getText().split("\n"); anzeigeMoves.add(" " + game.getUnicodeFromMove(l.getLast()) + ": " + l.getLast().toString() + "\n");
// es müssen immer mind 5 Zeilen existieren, dass also 1 Zug löschbar ist for (String line : anzeigeMoves) {
if (zeilen.length <= 2) sb.append(line);
return; }
StringBuilder sb = new StringBuilder(); ausgabe.setText(sb.toString());
for (int i = 0; i < zeilen.length - 1; i++) { }
sb.append(zeilen[i]).append("\n");
}
ausgabe.setText(sb.toString()); public void deleteLastAusgabe() {
} String[] zeilen = ausgabe.getText().split("\n");
private JPanel getUiPlayerOne() { // es müssen immer mind 5 Zeilen existieren, dass also 1 Zug löschbar ist
if (zeilen.length <= 2)
return;
JPanel playerOne = new JPanel(); StringBuilder sb = new StringBuilder();
playerOne.setBackground(new Color(90, 90, 90)); for (int i = 0; i < zeilen.length - 1; i++) {
playerOne.setLayout(new BoxLayout(playerOne, BoxLayout.Y_AXIS)); sb.append(zeilen[i]).append("\n");
}
playerOne.add(Box.createVerticalStrut(10)); ausgabe.setText(sb.toString());
}
// Button zurücknahme und aufgeben für Player 1 private JPanel getUiPlayerOne() {
JPanel aufgebenUndo = new JPanel();
aufgebenUndo.setBackground(new Color(90, 90, 90));
aufgebenUndo.setLayout(new BoxLayout(aufgebenUndo, BoxLayout.X_AXIS));
if (game.isZuruecknahme()) { JPanel playerOne = new JPanel();
undo2 = new JButton("Zug zurücknehmen"); playerOne.setBackground(new Color(90, 90, 90));
undo2.setBackground(Color.LIGHT_GRAY); playerOne.setLayout(new BoxLayout(playerOne, BoxLayout.Y_AXIS));
undo2.setForeground(Color.BLACK);
undo2.setFont(new Font("Tahoma", Font.BOLD, 16));
undo2.setAlignmentX(Component.CENTER_ALIGNMENT);
aufgebenUndo.add(undo2);
// Button-Listener playerOne.add(Box.createVerticalStrut(10));
undo2.addActionListener(new ButtonUndoMoveListener(this, this.game));
} // 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));
aufgebenUndo.add(Box.createHorizontalStrut(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);
JButton aufgeben = new JButton("Aufgeben"); // Button-Listener
aufgeben.setBackground(Color.LIGHT_GRAY); undo2.addActionListener(new ButtonUndoMoveListener(this, this.game));
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());
aufgebenUndo.add(Box.createHorizontalStrut(10)); aufgebenUndo.add(Box.createHorizontalStrut(10));
JButton safe = new JButton("Spielstand sichern"); JButton aufgeben = new JButton("Aufgeben");
safe.setBackground(Color.LIGHT_GRAY); aufgeben.setBackground(Color.LIGHT_GRAY);
safe.setForeground(Color.BLACK); aufgeben.setForeground(Color.BLACK);
safe.setFont(new Font("Tahoma", Font.BOLD, 16)); aufgeben.setFont(new Font("Tahoma", Font.BOLD, 16));
safe.setAlignmentX(Component.CENTER_ALIGNMENT); aufgeben.setAlignmentX(Component.CENTER_ALIGNMENT);
aufgebenUndo.add(safe); aufgebenUndo.add(aufgeben);
// Button-Listener // Button-Listener
safe.addActionListener(new ButtonFileSaverListener(this, this.game)); aufgeben.addActionListener(new ButtonAufgebenListener());
playerOne.add(aufgebenUndo); aufgebenUndo.add(Box.createHorizontalStrut(10));
playerOne.add(Box.createVerticalStrut(15)); 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);
JLabel clock1 = clock.getClock1(); // Button-Listener
playerOne.add(clock1); safe.addActionListener(new ButtonFileSaverListener(this, this.game));
playerOne.add(Box.createVerticalStrut(10)); playerOne.add(aufgebenUndo);
JLabel pl2 = new JLabel("Player 1:"); playerOne.add(Box.createVerticalStrut(15));
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);
return playerOne; JLabel clock1 = clock.getClock1();
} playerOne.add(clock1);
public void setBoardMode(BoardMode bm) { playerOne.add(Box.createVerticalStrut(10));
this.mode = bm;
}
public void setSelectedSquare(Square sq) { JLabel pl2 = new JLabel("Player 1:");
this.selectedSquare = sq; 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 HashMap<JButton, String> getBelegung() { return playerOne;
return this.belegungen; }
}
public JButton getUndo() { public void setBoardMode(BoardMode bm) {
return undo; this.mode = bm;
} }
public JButton getUndo2() { public void setSelectedSquare(Square sq) {
return undo2; this.selectedSquare = sq;
} }
public BoardMode getMode() { public HashMap<JButton, String> getBelegung() {
return mode; return this.belegungen;
} }
public Clock getClock() { public JButton getUndo() {
return clock; return undo;
} }
public JButton getUndo2() {
return undo2;
}
public BoardMode getMode() {
return mode;
}
public Clock getClock() {
return clock;
}
private void enableControlPanelButtons() {
for (Component c : this.controlPanel.getComponents()) {
if (c instanceof JButton) {
c.setEnabled(!c.isEnabled());
}
}
}
public void setViewPointer(int i) {
this.viewPointer = i;
}
public int getViewPointer() {
return this.viewPointer;
}
} }