Compare commits

..

No commits in common. "e6e1fa31873377a15342e47a253f38995d0b8cad" and "5ae9aef60550bf74f857f7cd9edcd1a2b00b5dbe" have entirely different histories.

4 changed files with 14 additions and 100 deletions

View File

@ -86,7 +86,7 @@ public class Controller {
selectedRow = modelRow;
selectedCol = modelCol;
gui.getField(guiRow, guiCol).setBorder(BorderFactory.createLineBorder(new Color(0x1b263b), 7));
gui.getField(guiRow, guiCol).setBorder(BorderFactory.createLineBorder(Color.RED, 2));
String fromSquare = coordToChessNotation(modelRow, modelCol);
List<MoveDTO> moves = engine.getLegalDestinations(fromSquare);
@ -94,7 +94,7 @@ public class Controller {
for (MoveDTO move : moves) {
int guiToRow = gui.isFlipped() ? 7 - move.getToRow() : move.getToRow();
int guiToCol = gui.isFlipped() ? 7 - move.getToCol() : move.getToCol();
gui.getField(guiToRow, guiToCol).setBackground(new Color( 27, 38, 59 ));
gui.getField(guiToRow, guiToCol).setBackground(Color.YELLOW);
highlightedFields.add(new int[]{guiToRow, guiToCol});
}
} else {
@ -113,13 +113,13 @@ public class Controller {
}
}
public void handleMove(MoveDTO move) {
if (engine.move(move)) {
updateGuiBoard();
//Züge in der MoveList aktualisieren
gui.updateMoveList(engine.getMoveListStringsGrouped());
//Spielstatus prüfen
if (engine.isMated()) {
String winner = engine.getCurrentPlayer().equals("WHITE") ? "SCHWARZ" : "WEIß";

View File

@ -9,8 +9,7 @@ import com.github.bhlangonijr.chesslib.move.Move;
public class ChessEngine {
private Board board;
private List<Move> moves = new ArrayList<>();
public ChessEngine() {
board = new Board();
}
@ -21,7 +20,6 @@ public class ChessEngine {
Move libMove = new Move(Square.valueOf(from), Square.valueOf(to));
if (board.legalMoves().contains(libMove)) {
board.doMove(libMove);
moves.add(libMove); // <-- hier merken!
return true;
}
return false;
@ -42,20 +40,6 @@ public class ChessEngine {
return destinations;
}
public List<String> getMoveListStringsGrouped() {
List<String> result = new ArrayList<>();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < moves.size(); i++) {
if (i % 2 == 0) sb.append((i/2 + 1) + ". ");
sb.append(moves.get(i).toString()).append(" ");
if (i % 2 == 1 || i == moves.size() - 1) {
result.add(sb.toString().trim());
sb = new StringBuilder();
}
}
return result;
}
public PieceDTO getPieceAt(String square) {
Piece piece = board.getPiece(Square.valueOf(square.toUpperCase()));
return convertPieceToDTO(piece);

View File

@ -1,6 +1,5 @@
package de.hs_mannheim.informatik.chess.view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
@ -8,15 +7,12 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import de.hs_mannheim.informatik.chess.model.BoardDTO;
@ -27,12 +23,8 @@ public class GameGui {
private JLabel[][] fields = new JLabel[8][8];
private JButton flipBoardButton;
private boolean isFlipped = false;
private JPanel moveListPanel;
private JScrollPane moveListScroll;
public GameGui(){
initFields();
mainFrame();
}
@ -48,22 +40,6 @@ public class GameGui {
return frame;
}
private void initFields() {
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 8; col++) {
JLabel label = new JLabel("", SwingConstants.CENTER);
label.setOpaque(true);
label.setFont(new Font("Serif", Font.BOLD, 40));
if ((row + col) % 2 == 0) {
label.setBackground(new Color(0x778da9));
} else {
label.setBackground(new Color(0xe0e1dd));
}
fields[row][col] = label;
}
}
}
public JPanel mainPanel() {
JPanel mainPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
@ -76,7 +52,7 @@ public class GameGui {
gbc.insets = new Insets(5, 5, 5, 0);
//oben, links, unten, rechts
gbc.fill = GridBagConstraints.BOTH;
mainPanel.add(chessPanel(boardPanel()), gbc);
mainPanel.add(chessPanel(boardPanel()),gbc);
// Rechts (Stats)
gbc.gridx = 1;
@ -101,7 +77,7 @@ public class GameGui {
JLabel label = new JLabel("", SwingConstants.CENTER);
label.setOpaque(true);
label.setFont(new Font("Serif", Font.BOLD, 70));
label.setFont(new Font("Serif", Font.BOLD, 40));
if ((row + col) % 2 == 0) {
label.setBackground(new Color(0x778da9));
} else {
@ -115,7 +91,7 @@ public class GameGui {
boardPanel.setBackground(new Color(0x1b263b));
return boardPanel;
}
public JPanel chessPanel(JPanel panel) {
JPanel chessPanel = new JPanel(new GridBagLayout());
GridBagConstraints board = new GridBagConstraints();
@ -150,55 +126,9 @@ public class GameGui {
}
public JPanel statsPanel() {
JPanel statsPanel = new JPanel(new BorderLayout());
statsPanel.setBackground(new Color(0x0d1b2a));
// Move-Liste (scrollbar, wie gehabt)
moveListPanel = new JPanel();
moveListPanel.setLayout(new BoxLayout(moveListPanel, BoxLayout.Y_AXIS));
moveListPanel.setBackground(new Color(0x0d1b2a));
moveListScroll = new JScrollPane(moveListPanel);
moveListScroll.setPreferredSize(new Dimension(250, 800));
statsPanel.add(moveListScroll, BorderLayout.CENTER);
// Button-Leiste
JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(new Color(0x0d1b2a));
// Grid oder Flow je nach Geschmack
buttonPanel.setLayout(new GridLayout(1, 4, 10, 0));
JButton btnFirst = new JButton("|<");
JButton btnPrev = new JButton("<");
JButton btnNext = new JButton(">");
JButton btnLast = new JButton(">|");
// Style (optional)
btnFirst.setBackground(new Color(0x212529)); btnFirst.setForeground(Color.WHITE);
btnPrev.setBackground(new Color(0x212529)); btnPrev.setForeground(Color.WHITE);
btnNext.setBackground(new Color(0x212529)); btnNext.setForeground(Color.WHITE);
btnLast.setBackground(new Color(0x212529)); btnLast.setForeground(Color.WHITE);
// Hinzufügen
buttonPanel.add(btnFirst);
buttonPanel.add(btnPrev);
buttonPanel.add(btnNext);
buttonPanel.add(btnLast);
// Unten ins BorderLayout
statsPanel.add(buttonPanel, BorderLayout.SOUTH);
return statsPanel;
}
public void updateMoveList(List<String> moves) {
moveListPanel.removeAll();
for (String move : moves) {
JLabel moveLabel = new JLabel(move);
moveLabel.setForeground(Color.WHITE);
moveLabel.setFont(new Font("SansSerif", Font.PLAIN, 18));
moveListPanel.add(moveLabel);
}
moveListPanel.revalidate();
moveListPanel.repaint();
JPanel statsPanel = new JPanel();
statsPanel.setBackground(new Color(0x0d1b2a));
return statsPanel;
}
public JLabel getField(int row, int col) {

View File

@ -26,7 +26,7 @@ public class MainGui {
gbc.insets = new Insets(15, 0, 15, 0);
//Title
JLabel title = new JLabel("ChessDE", SwingConstants.CENTER);
JLabel title = new JLabel("Chess", SwingConstants.CENTER);
title.setFont(new Font("Serif", Font.BOLD, 150));
title.setForeground(new Color(0x1b263b));
gbc.gridy = 0;