Fixed wrong chessboard square colors
parent
532059ba0b
commit
4fe9a8ad8a
|
|
@ -144,27 +144,37 @@ public class GameController {
|
||||||
boolean isWhitePromotion = isPawn && piece.getColor().equals("WHITE") && move.getToRow() == 0;
|
boolean isWhitePromotion = isPawn && piece.getColor().equals("WHITE") && move.getToRow() == 0;
|
||||||
boolean isBlackPromotion = isPawn && piece.getColor().equals("BLACK") && move.getToRow() == 7;
|
boolean isBlackPromotion = isPawn && piece.getColor().equals("BLACK") && move.getToRow() == 7;
|
||||||
|
|
||||||
|
boolean success = false;
|
||||||
|
|
||||||
if (isWhitePromotion || isBlackPromotion) {
|
if (isWhitePromotion || isBlackPromotion) {
|
||||||
String color = piece.getColor().equals("WHITE") ? "Weiß" : "Schwarz";
|
String color = piece.getColor().equals("WHITE") ? "Weiß" : "Schwarz";
|
||||||
String promotion = gui.showPromotionDialog(color);
|
String promotion = gui.showPromotionDialog(color);
|
||||||
if (engine.moveWithPromotion(move, promotion)) {
|
success = engine.moveWithPromotion(move, promotion);
|
||||||
updateGuiBoard();
|
if (!success) {
|
||||||
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
|
||||||
} else {
|
|
||||||
gui.displayMessage("Ungültiger Promotionszug!");
|
gui.displayMessage("Ungültiger Promotionszug!");
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
success = engine.move(move);
|
||||||
|
if (!success) {
|
||||||
|
gui.displayMessage("Ungültiger Zug!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Normale Züge wie gehabt:
|
|
||||||
if (engine.move(move)) {
|
|
||||||
updateGuiBoard();
|
updateGuiBoard();
|
||||||
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
gui.updateMoveList(engine.getMoveListStringsGrouped());
|
||||||
} else {
|
|
||||||
gui.displayMessage("Ungültiger Zug!");
|
// ---- HIER ist die Matt/Patt/Remis-Prüfung ----
|
||||||
|
if (engine.isMated()) {
|
||||||
|
String winner = engine.getCurrentPlayer().equals("WHITE") ? "SCHWARZ" : "WEIß";
|
||||||
|
gui.displayMessage(winner + " hat gewonnen (Schachmatt)!");
|
||||||
|
} else if (engine.isStalemate() || engine.isDraw()) {
|
||||||
|
gui.displayMessage("Remis! (Stalemate oder andere Regel)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void updateGuiBoard() {
|
public void updateGuiBoard() {
|
||||||
BoardDTO board = engine.getBoardAsDTO();
|
BoardDTO board = engine.getBoardAsDTO();
|
||||||
gui.updateBoard(board);
|
gui.updateBoard(board);
|
||||||
|
|
@ -179,10 +189,13 @@ public class GameController {
|
||||||
|
|
||||||
|
|
||||||
private void resetFieldBackground(int row, int col) {
|
private void resetFieldBackground(int row, int col) {
|
||||||
|
Color LIGHT = new Color(0xe0e1dd);
|
||||||
|
Color DARK = new Color(0x778da9);
|
||||||
if ((row + col) % 2 == 0) {
|
if ((row + col) % 2 == 0) {
|
||||||
gui.getField(row, col).setBackground(new Color(0x778da9));
|
gui.getField(row, col).setBackground(LIGHT);
|
||||||
} else {
|
} else {
|
||||||
gui.getField(row, col).setBackground(new Color(0xe0e1dd));
|
gui.getField(row, col).setBackground(DARK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,9 @@ public class GameGui {
|
||||||
JButton btnNext = new JButton(">");
|
JButton btnNext = new JButton(">");
|
||||||
JButton btnLast = new JButton(">|");
|
JButton btnLast = new JButton(">|");
|
||||||
|
|
||||||
|
Color LIGHT = new Color(0xe0e1dd);
|
||||||
|
Color DARK = new Color(0x778da9);
|
||||||
|
|
||||||
private JPanel moveListPanel;
|
private JPanel moveListPanel;
|
||||||
private JScrollPane moveListScroll;
|
private JScrollPane moveListScroll;
|
||||||
|
|
||||||
|
|
@ -59,10 +62,11 @@ 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, 40));
|
label.setFont(new Font("Serif", Font.BOLD, 40));
|
||||||
|
// Richtige Schachfärbung:
|
||||||
if ((row + col) % 2 == 0) {
|
if ((row + col) % 2 == 0) {
|
||||||
label.setBackground(new Color(0x778da9));
|
label.setBackground(LIGHT); // a1 ist jetzt hell!
|
||||||
} else {
|
} else {
|
||||||
label.setBackground(new Color(0xe0e1dd));
|
label.setBackground(DARK);
|
||||||
}
|
}
|
||||||
fields[row][col] = label;
|
fields[row][col] = label;
|
||||||
}
|
}
|
||||||
|
|
@ -101,20 +105,18 @@ public class GameGui {
|
||||||
boardPanel.setPreferredSize(new Dimension(800, 800));
|
boardPanel.setPreferredSize(new Dimension(800, 800));
|
||||||
|
|
||||||
for (int row = 0; row < 8; row++) {
|
for (int row = 0; row < 8; row++) {
|
||||||
|
|
||||||
for (int col = 0; col < 8; col++) {
|
for (int col = 0; col < 8; col++) {
|
||||||
|
|
||||||
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, 70));
|
||||||
|
// Richtige Schachfärbung:
|
||||||
if ((row + col) % 2 == 0) {
|
if ((row + col) % 2 == 0) {
|
||||||
label.setBackground(new Color(0x778da9));
|
label.setBackground(LIGHT);
|
||||||
} else {
|
} else {
|
||||||
label.setBackground(new Color(0xe0e1dd));
|
label.setBackground(DARK);
|
||||||
}
|
}
|
||||||
fields[row][col] = label;
|
fields[row][col] = label;
|
||||||
boardPanel.add(label);
|
boardPanel.add(label);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boardPanel.setBackground(new Color(0x1b263b));
|
boardPanel.setBackground(new Color(0x1b263b));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue