Ausgabe von gezogenen Zügen verschönert.

devUi
Your Name 2025-06-23 18:30:34 +02:00
parent 6c748bcaa5
commit d4e56ea2b6
3 changed files with 52 additions and 47 deletions

View File

@ -1,6 +1,5 @@
package de.mannheim.th.chess.controller; package de.mannheim.th.chess.controller;
import java.awt.Color;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -39,16 +38,8 @@ public class ButtonMovePieceListener implements ActionListener {
this.sf.erstelleBrett(); this.sf.erstelleBrett();
if (game.getLastMove() != null) { if (game.getLastMove() != null) {
char[] z = game.getLastMove().toString().toCharArray();
String moveString = "";
if(game.getActivePlayer() == 1) {
moveString = " " + String.valueOf(z[0]) + String.valueOf(z[1]) + " -> " + String.valueOf(z[2]) + String.valueOf(z[3]);
}else if(game.getActivePlayer() == 2){
moveString = String.valueOf(z[0]) + String.valueOf(z[1]) + " -> " + String.valueOf(z[2]) + String.valueOf(z[3]+" ");
}
sf.aktualisiereAusgabe();
sf.appendText(moveString);
} }
} }
} }

View File

@ -202,4 +202,8 @@ public class Game {
logger.info(this.movelist.getLast().toString()); logger.info(this.movelist.getLast().toString());
return this.movelist.getLast(); return this.movelist.getLast();
} }
public MoveList getMoveList() {
return this.movelist;
}
} }

View File

@ -5,6 +5,7 @@ import org.apache.logging.log4j.Logger;
import com.github.bhlangonijr.chesslib.Square; import com.github.bhlangonijr.chesslib.Square;
import com.github.bhlangonijr.chesslib.move.Move; import com.github.bhlangonijr.chesslib.move.Move;
import com.github.bhlangonijr.chesslib.move.MoveList;
import de.mannheim.th.chess.App; import de.mannheim.th.chess.App;
import de.mannheim.th.chess.domain.Game; import de.mannheim.th.chess.domain.Game;
@ -56,17 +57,12 @@ public class SpielFrame extends JFrame {
private Clock clock; private Clock clock;
private BoardMode mode; private BoardMode mode;
private Zuruecknahme undoMove;
private Square selectedSquare; private Square selectedSquare;
public enum BoardMode { public enum BoardMode {
normal, pieceSelected, finished normal, pieceSelected, finished
} }
public enum Zuruecknahme {
white, black, nobody
}
/** /**
* Create the frame. * Create the frame.
*/ */
@ -333,7 +329,6 @@ public class SpielFrame extends JFrame {
undo.addActionListener(new ButtonUndoMoveListener(this, this.game)); undo.addActionListener(new ButtonUndoMoveListener(this, this.game));
} }
aufgebenUndo.add(Box.createHorizontalStrut(10)); aufgebenUndo.add(Box.createHorizontalStrut(10));
JButton aufgeben = new JButton("Aufgeben"); JButton aufgeben = new JButton("Aufgeben");
@ -375,9 +370,9 @@ public class SpielFrame extends JFrame {
ausgabe.setEditable(false); ausgabe.setEditable(false);
ausgabe.setBackground(new Color(75, 75, 75)); ausgabe.setBackground(new Color(75, 75, 75));
ausgabe.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); ausgabe.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
ausgabe.setFont(new Font("Calibri", Font.BOLD, 26)); ausgabe.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 20));
ausgabe.setForeground(Color.BLACK); ausgabe.setForeground(Color.BLACK);
ausgabe.setText("\n Bisherige Züge:\n"); ausgabe.setText("\n Bisherige Züge:\n");
JScrollPane scrollPane = new JScrollPane(ausgabe); JScrollPane scrollPane = new JScrollPane(ausgabe);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
@ -387,18 +382,37 @@ public class SpielFrame extends JFrame {
return statistik; return statistik;
} }
public void appendText(String text) { public void aktualisiereAusgabe() {
ausgabe.append(" "+ text + "\n"); StringBuilder sb = new StringBuilder();
sb.append("\n Bisherige Züge:\n");
sb.append(" +------------------+------------------+\n");
sb.append(" | Player 1: | Player 2: |\n");
sb.append(" +------------------+------------------+\n");
MoveList l = game.getMoveList();
for (int i = 0; i < l.size(); i += 2) {
String p1 = l.get(i).toString();
String p2 = (i + 1 < l.size()) ? l.get(i + 1).toString() : "";
sb.append(String.format(" | %-17s| %-17s|\n", p1, p2));
sb.append(" +------------------+------------------+\n");
}
ausgabe.setText(sb.toString());
} }
public void deleteLastAusgabe() { public void deleteLastAusgabe() {
String[] ausgabe = this.ausgabe.getText().split("\n"); String[] zeilen = ausgabe.getText().split("\n");
String textNeu = "";
for(int i=0;i<ausgabe.length-1;i++) { //es müssen immer mind 5 Zeilen existieren, dass also 1 Zug löschbar ist
textNeu += ausgabe[i]+"\n"; if (zeilen.length <= 5) return;
}
this.ausgabe.setText(""); StringBuilder sb = new StringBuilder();
appendText(textNeu); for (int i = 0; i < zeilen.length - 2; i++) {
sb.append(zeilen[i]).append("\n");
}
ausgabe.setText(sb.toString());
} }
private JPanel getUiPlayerOne() { private JPanel getUiPlayerOne() {
@ -482,10 +496,6 @@ public class SpielFrame extends JFrame {
return this.belegungen; return this.belegungen;
} }
public void setZuruecknahme(Zuruecknahme z) {
this.undoMove = z;
}
public JButton getUndo() { public JButton getUndo() {
return undo; return undo;
} }