Updated code comments for better clarity
parent
93570f2c1c
commit
11cede7678
|
|
@ -40,14 +40,14 @@ public class Controller {
|
||||||
final int r = row, c = col;
|
final int r = row, c = col;
|
||||||
gui.getField(row, col).addMouseListener(new MouseAdapter() {
|
gui.getField(row, col).addMouseListener(new MouseAdapter() {
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
handleClick(r, c); // NICHT flippen!
|
handleClick(r, c);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.getFlipBoardButton().addActionListener(e -> {
|
gui.getFlipBoardButton().addActionListener(e -> {
|
||||||
// 1. ALLE Highlights und Borders zurücksetzen (GUI-Koordinaten!)
|
//ALLE Highlights und Borders zurücksetzen
|
||||||
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++) {
|
||||||
resetFieldBackground(row, col);
|
resetFieldBackground(row, col);
|
||||||
|
|
@ -72,15 +72,15 @@ public class Controller {
|
||||||
int modelRow = flipRow(guiRow);
|
int modelRow = flipRow(guiRow);
|
||||||
int modelCol = flipCol(guiCol);
|
int modelCol = flipCol(guiCol);
|
||||||
|
|
||||||
// --- NEU: Figur am Feld?
|
//Figur am Feld
|
||||||
BoardDTO boardDTO = engine.getBoardAsDTO();
|
BoardDTO boardDTO = engine.getBoardAsDTO();
|
||||||
PieceDTO piece = boardDTO.getBoard()[modelRow][modelCol];
|
PieceDTO piece = boardDTO.getBoard()[modelRow][modelCol];
|
||||||
|
|
||||||
// --- NEU: Ist eine Figur da und hat sie die aktuelle Farbe?
|
//Ist eine Figur da und hat sie die aktuelle Farbe
|
||||||
String amZug = engine.getCurrentPlayer(); // "WHITE" oder "BLACK"
|
String amZug = engine.getCurrentPlayer(); // "WHITE" oder "BLACK"
|
||||||
if (selectedRow == -1 && selectedCol == -1) {
|
if (selectedRow == -1 && selectedCol == -1) {
|
||||||
if (piece == null || !piece.getColor().equals(amZug)) {
|
if (piece == null || !piece.getColor().equals(amZug)) {
|
||||||
// Falsche Farbe oder leeres Feld → abbrechen, keine Highlights!
|
// Falsche Farbe oder leeres Feld -> abbrechen, keine Highlights!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,7 +98,6 @@ public class Controller {
|
||||||
highlightedFields.add(new int[]{guiToRow, guiToCol});
|
highlightedFields.add(new int[]{guiToRow, guiToCol});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// ... wie gehabt ...
|
|
||||||
for (int[] xy : highlightedFields) {
|
for (int[] xy : highlightedFields) {
|
||||||
resetFieldBackground(xy[0], xy[1]);
|
resetFieldBackground(xy[0], xy[1]);
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +120,7 @@ public class Controller {
|
||||||
if (engine.move(move)) {
|
if (engine.move(move)) {
|
||||||
updateGuiBoard();
|
updateGuiBoard();
|
||||||
|
|
||||||
// Jetzt: 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ß";
|
||||||
gui.displayMessage(winner + " hat gewonnen (Schachmatt)!");
|
gui.displayMessage(winner + " hat gewonnen (Schachmatt)!");
|
||||||
|
|
@ -135,7 +134,7 @@ public class Controller {
|
||||||
|
|
||||||
public void updateGuiBoard() {
|
public void updateGuiBoard() {
|
||||||
BoardDTO board = engine.getBoardAsDTO();
|
BoardDTO board = engine.getBoardAsDTO();
|
||||||
gui.updateBoard(board); // Passe die GUI an, damit sie ein BoardDTO nimmt!
|
gui.updateBoard(board); // Passe die GUI an
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hilfsmethode, um von Koordinaten (row/col) auf z.B. "E2" zu kommen
|
// Hilfsmethode, um von Koordinaten (row/col) auf z.B. "E2" zu kommen
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue