Lösenanzeige verbessert

currentStatus
Vickvick2002 2025-01-05 14:18:05 +01:00
parent 4cb6b12814
commit 3d0f808daf
3 changed files with 11 additions and 17 deletions

View File

@ -5,7 +5,6 @@ import java.util.List;
/**
* Validates the Hitori board against the solution.
*/
public class HitoriValidator {
private final HitoriBoard board;
@ -19,7 +18,6 @@ public class HitoriValidator {
* @param solutionCoordinates The coordinates of the correct black cells in "row,column" format.
* @return true if the current board matches the solution, false otherwise.
*/
public boolean validateBoard(List<String> solutionCoordinates) {
for (String coordinate : solutionCoordinates) {
String[] parts = coordinate.split(",");
@ -33,9 +31,15 @@ public class HitoriValidator {
for (int i = 0; i < board.getSize(); i++) {
for (int j = 0; j < board.getSize(); j++) {
if (board.getCell(i,j).getState() == HitoriCell.CellState.BLACK &&
HitoriCell cell = board.getCell(i, j);
if (cell.getState() == HitoriCell.CellState.BLACK &&
!solutionCoordinates.contains((i + 1) + "," + (j + 1))) {
return false;
return false; // Ein schwarzes Feld gehört nicht zur Lösung
}
// Überprüfe, ob alle nicht schwarzen Felder weiß sind
if (cell.getState() != HitoriCell.CellState.BLACK && cell.getState() != HitoriCell.CellState.WHITE) {
return false; // Es gibt noch graue Felder
}
}
}

View File

@ -154,13 +154,7 @@ public class GameBoard extends JPanel {
public boolean validateCurrentBoard() {
HitoriValidator validator = new HitoriValidator(board);
if (validator.validateBoard(board.getSolutionCoordinates())) {
JOptionPane.showMessageDialog(this, "Das Spielfeld ist korrekt gelöst!", "Erfolg", JOptionPane.INFORMATION_MESSAGE);
return true;
} else {
JOptionPane.showMessageDialog(this, "Das Spielfeld enthält Fehler!", "Fehler", JOptionPane.ERROR_MESSAGE);
return false;
}
return validator.validateBoard(board.getSolutionCoordinates());
}
private void showPauseMenu() {

View File

@ -111,8 +111,9 @@ public class StartMenu extends JPanel {
new HighscoreDialog((JFrame) SwingUtilities.getWindowAncestor(this)).setVisible(true);
}
// Hilfsmethoden
// Hilfsmethoden
private void loadGameBoard(GameBoard gameBoard, List<String> solutionCoordinates) {
removeAll();
setLayout(new BorderLayout());
@ -140,9 +141,4 @@ public class StartMenu extends JPanel {
JOptionPane.showMessageDialog(this, "Fehler beim Laden des Spielfelds: " + e.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE);
}
}
}