Compare commits
No commits in common. "e6e1fa31873377a15342e47a253f38995d0b8cad" and "5ae9aef60550bf74f857f7cd9edcd1a2b00b5dbe" have entirely different histories.
e6e1fa3187
...
5ae9aef605
|
|
@ -86,7 +86,7 @@ public class Controller {
|
||||||
|
|
||||||
selectedRow = modelRow;
|
selectedRow = modelRow;
|
||||||
selectedCol = modelCol;
|
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);
|
String fromSquare = coordToChessNotation(modelRow, modelCol);
|
||||||
List<MoveDTO> moves = engine.getLegalDestinations(fromSquare);
|
List<MoveDTO> moves = engine.getLegalDestinations(fromSquare);
|
||||||
|
|
@ -94,7 +94,7 @@ public class Controller {
|
||||||
for (MoveDTO move : moves) {
|
for (MoveDTO move : moves) {
|
||||||
int guiToRow = gui.isFlipped() ? 7 - move.getToRow() : move.getToRow();
|
int guiToRow = gui.isFlipped() ? 7 - move.getToRow() : move.getToRow();
|
||||||
int guiToCol = gui.isFlipped() ? 7 - move.getToCol() : move.getToCol();
|
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});
|
highlightedFields.add(new int[]{guiToRow, guiToCol});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -113,13 +113,13 @@ public class Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void handleMove(MoveDTO move) {
|
public void handleMove(MoveDTO move) {
|
||||||
if (engine.move(move)) {
|
if (engine.move(move)) {
|
||||||
updateGuiBoard();
|
updateGuiBoard();
|
||||||
|
|
||||||
//Züge in der MoveList aktualisieren
|
|
||||||
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
|
||||||
|
|
||||||
//Spielstatus prüfen
|
//Spielstatus prüfen
|
||||||
if (engine.isMated()) {
|
if (engine.isMated()) {
|
||||||
String winner = engine.getCurrentPlayer().equals("WHITE") ? "SCHWARZ" : "WEIß";
|
String winner = engine.getCurrentPlayer().equals("WHITE") ? "SCHWARZ" : "WEIß";
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import com.github.bhlangonijr.chesslib.move.Move;
|
||||||
|
|
||||||
public class ChessEngine {
|
public class ChessEngine {
|
||||||
private Board board;
|
private Board board;
|
||||||
private List<Move> moves = new ArrayList<>();
|
|
||||||
|
|
||||||
public ChessEngine() {
|
public ChessEngine() {
|
||||||
board = new Board();
|
board = new Board();
|
||||||
|
|
@ -21,7 +20,6 @@ public class ChessEngine {
|
||||||
Move libMove = new Move(Square.valueOf(from), Square.valueOf(to));
|
Move libMove = new Move(Square.valueOf(from), Square.valueOf(to));
|
||||||
if (board.legalMoves().contains(libMove)) {
|
if (board.legalMoves().contains(libMove)) {
|
||||||
board.doMove(libMove);
|
board.doMove(libMove);
|
||||||
moves.add(libMove); // <-- hier merken!
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -42,20 +40,6 @@ public class ChessEngine {
|
||||||
return destinations;
|
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) {
|
public PieceDTO getPieceAt(String square) {
|
||||||
Piece piece = board.getPiece(Square.valueOf(square.toUpperCase()));
|
Piece piece = board.getPiece(Square.valueOf(square.toUpperCase()));
|
||||||
return convertPieceToDTO(piece);
|
return convertPieceToDTO(piece);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package de.hs_mannheim.informatik.chess.view;
|
package de.hs_mannheim.informatik.chess.view;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
|
@ -8,15 +7,12 @@ import java.awt.GridBagConstraints;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.BoxLayout;
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.chess.model.BoardDTO;
|
import de.hs_mannheim.informatik.chess.model.BoardDTO;
|
||||||
|
|
@ -28,11 +24,7 @@ public class GameGui {
|
||||||
private JButton flipBoardButton;
|
private JButton flipBoardButton;
|
||||||
private boolean isFlipped = false;
|
private boolean isFlipped = false;
|
||||||
|
|
||||||
private JPanel moveListPanel;
|
|
||||||
private JScrollPane moveListScroll;
|
|
||||||
|
|
||||||
public GameGui(){
|
public GameGui(){
|
||||||
initFields();
|
|
||||||
mainFrame();
|
mainFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,22 +40,6 @@ public class GameGui {
|
||||||
return frame;
|
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() {
|
public JPanel mainPanel() {
|
||||||
JPanel mainPanel = new JPanel(new GridBagLayout());
|
JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||||
GridBagConstraints gbc = new GridBagConstraints();
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
|
|
@ -76,7 +52,7 @@ public class GameGui {
|
||||||
gbc.insets = new Insets(5, 5, 5, 0);
|
gbc.insets = new Insets(5, 5, 5, 0);
|
||||||
//oben, links, unten, rechts
|
//oben, links, unten, rechts
|
||||||
gbc.fill = GridBagConstraints.BOTH;
|
gbc.fill = GridBagConstraints.BOTH;
|
||||||
mainPanel.add(chessPanel(boardPanel()), gbc);
|
mainPanel.add(chessPanel(boardPanel()),gbc);
|
||||||
|
|
||||||
// Rechts (Stats)
|
// Rechts (Stats)
|
||||||
gbc.gridx = 1;
|
gbc.gridx = 1;
|
||||||
|
|
@ -101,7 +77,7 @@ public class GameGui {
|
||||||
|
|
||||||
JLabel label = new JLabel("", SwingConstants.CENTER);
|
JLabel label = new JLabel("", SwingConstants.CENTER);
|
||||||
label.setOpaque(true);
|
label.setOpaque(true);
|
||||||
label.setFont(new Font("Serif", Font.BOLD, 70));
|
label.setFont(new Font("Serif", Font.BOLD, 40));
|
||||||
if ((row + col) % 2 == 0) {
|
if ((row + col) % 2 == 0) {
|
||||||
label.setBackground(new Color(0x778da9));
|
label.setBackground(new Color(0x778da9));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -150,57 +126,11 @@ public class GameGui {
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPanel statsPanel() {
|
public JPanel statsPanel() {
|
||||||
JPanel statsPanel = new JPanel(new BorderLayout());
|
JPanel statsPanel = new JPanel();
|
||||||
statsPanel.setBackground(new Color(0x0d1b2a));
|
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;
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
public JLabel getField(int row, int col) {
|
public JLabel getField(int row, int col) {
|
||||||
return fields[row][col];
|
return fields[row][col];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ public class MainGui {
|
||||||
gbc.insets = new Insets(15, 0, 15, 0);
|
gbc.insets = new Insets(15, 0, 15, 0);
|
||||||
|
|
||||||
//Title
|
//Title
|
||||||
JLabel title = new JLabel("ChessDE", SwingConstants.CENTER);
|
JLabel title = new JLabel("Chess", SwingConstants.CENTER);
|
||||||
title.setFont(new Font("Serif", Font.BOLD, 150));
|
title.setFont(new Font("Serif", Font.BOLD, 150));
|
||||||
title.setForeground(new Color(0x1b263b));
|
title.setForeground(new Color(0x1b263b));
|
||||||
gbc.gridy = 0;
|
gbc.gridy = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue