Ausgabe gezogener Züge jetzt korrekt

devUiNew
Your Name 2025-06-24 10:39:23 +02:00
parent 346b413a7d
commit f0fdbb0668
1 changed files with 441 additions and 437 deletions

View File

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