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;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@ -39,16 +38,8 @@ public class ButtonMovePieceListener implements ActionListener {
this.sf.erstelleBrett();
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.appendText(moveString);
sf.aktualisiereAusgabe();
}
}
}

View File

@ -202,4 +202,8 @@ public class Game {
logger.info(this.movelist.getLast().toString());
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.move.Move;
import com.github.bhlangonijr.chesslib.move.MoveList;
import de.mannheim.th.chess.App;
import de.mannheim.th.chess.domain.Game;
@ -56,17 +57,12 @@ public class SpielFrame extends JFrame {
private Clock clock;
private BoardMode mode;
private Zuruecknahme undoMove;
private Square selectedSquare;
public enum BoardMode {
normal, pieceSelected, finished
}
public enum Zuruecknahme {
white, black, nobody
}
/**
* Create the frame.
*/
@ -333,7 +329,6 @@ public class SpielFrame extends JFrame {
undo.addActionListener(new ButtonUndoMoveListener(this, this.game));
}
aufgebenUndo.add(Box.createHorizontalStrut(10));
JButton aufgeben = new JButton("Aufgeben");
@ -375,7 +370,7 @@ public class SpielFrame extends JFrame {
ausgabe.setEditable(false);
ausgabe.setBackground(new Color(75, 75, 75));
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.setText("\n Bisherige Züge:\n");
@ -387,18 +382,37 @@ public class SpielFrame extends JFrame {
return statistik;
}
public void appendText(String text) {
ausgabe.append(" "+ text + "\n");
public void aktualisiereAusgabe() {
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");
}
public void deleteLastAusgabe() {
String[] ausgabe = this.ausgabe.getText().split("\n");
String textNeu = "";
for(int i=0;i<ausgabe.length-1;i++) {
textNeu += ausgabe[i]+"\n";
ausgabe.setText(sb.toString());
}
this.ausgabe.setText("");
appendText(textNeu);
public void deleteLastAusgabe() {
String[] zeilen = ausgabe.getText().split("\n");
//es müssen immer mind 5 Zeilen existieren, dass also 1 Zug löschbar ist
if (zeilen.length <= 5) return;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < zeilen.length - 2; i++) {
sb.append(zeilen[i]).append("\n");
}
ausgabe.setText(sb.toString());
}
private JPanel getUiPlayerOne() {
@ -482,10 +496,6 @@ public class SpielFrame extends JFrame {
return this.belegungen;
}
public void setZuruecknahme(Zuruecknahme z) {
this.undoMove = z;
}
public JButton getUndo() {
return undo;
}