Code erweitert
parent
9267aec8e4
commit
2205f1bf04
|
@ -8,6 +8,9 @@ import java.awt.*;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import static PR2.HitoriSpiel.GUI.BoardLoader.loadBoard;
|
||||
|
||||
public class StartMenu extends JFrame {
|
||||
private JPanel mainPanel;
|
||||
|
@ -95,7 +98,7 @@ public class StartMenu extends JFrame {
|
|||
System.out.println("Lade Datei von Pfad: " + resourcePath);
|
||||
|
||||
|
||||
int[][] boardData = BoardLoader.loadBoard(resourcePath);
|
||||
int[][] boardData = loadBoard(resourcePath);
|
||||
List<String> solutionCoordinates = HitoriSolutionLoader.loadSolution(resourcePath);
|
||||
|
||||
HitoriBoard hitoriBoard = new HitoriBoard(boardData, solutionCoordinates); // Stelle sicher, dass die Lösung korrekt geladen wird
|
||||
|
@ -103,7 +106,7 @@ public class StartMenu extends JFrame {
|
|||
|
||||
loadGameBoard2(gameBoard, solutionCoordinates);
|
||||
//loadGameBoard(boardData);
|
||||
addGameControls(gameBoard);
|
||||
// addGameControls(gameBoard);
|
||||
|
||||
System.out.println("Verfügbare Spielfelder: " + boardFileNames);
|
||||
System.out.println("Ausgewählte Datei: " + selectedFile);
|
||||
|
@ -119,10 +122,46 @@ public class StartMenu extends JFrame {
|
|||
}
|
||||
|
||||
private void randomBoard() {
|
||||
// TODO: Logik zum Auswählen eines zufälligen Spielfeldes implementieren
|
||||
JOptionPane.showMessageDialog(this, "Zufälliges Spielfeld wurde angeklickt");
|
||||
// Lade alle verfügbaren Spielfeld-Dateien
|
||||
List<String> boardFileNames = BoardLoader.loadBoardsAsList();
|
||||
|
||||
// Überprüfe, ob Dateien verfügbar sind
|
||||
if (boardFileNames.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "Keine Spielfelder gefunden.", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
// Wähle eine zufällige Datei
|
||||
String randomFile = boardFileNames.get(new Random().nextInt(boardFileNames.size()));
|
||||
System.out.println("Zufällige Datei gewählt: " + randomFile);
|
||||
|
||||
try {
|
||||
// Lade das zufällige Spielfeld
|
||||
String resourcePath = "/persistent/Hitori_Spielfelder/" + randomFile;
|
||||
System.out.println("Lade Datei von Pfad: " + resourcePath);
|
||||
|
||||
InputStream inputStream = getClass().getResourceAsStream(resourcePath);
|
||||
if (inputStream == null) {
|
||||
throw new IOException("Ressourcendatei nicht gefunden: " + resourcePath);
|
||||
}
|
||||
|
||||
// Spielfeld-Daten laden
|
||||
int[][] boardData = BoardLoader.loadBoard(resourcePath);
|
||||
List<String> solutionCoordinates = HitoriSolutionLoader.loadSolution(resourcePath);
|
||||
|
||||
// Spielfeld erstellen und anzeigen
|
||||
HitoriBoard hitoriBoard = new HitoriBoard(boardData, solutionCoordinates);
|
||||
GameBoard gameBoard = new GameBoard(hitoriBoard);
|
||||
loadGameBoard2(gameBoard, solutionCoordinates);
|
||||
|
||||
} catch (IOException e) {
|
||||
// Fehler beim Laden des Spielfelds
|
||||
JOptionPane.showMessageDialog(this, "Fehler beim Laden des Spielfelds: " + e.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void highscorelist() {
|
||||
// TODO: Logik zur Anzeige der Highscoreliste implementieren
|
||||
JOptionPane.showMessageDialog(this, "Highscoreliste wurde angeklickt");
|
||||
|
@ -152,54 +191,5 @@ public class StartMenu extends JFrame {
|
|||
mainPanel.repaint();
|
||||
}
|
||||
|
||||
private void addGameControls(GameBoard gameBoard) {
|
||||
JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); // Buttons zentriert anordnen
|
||||
|
||||
// "Zurücksetzen"-Button
|
||||
JButton resetButton = createButton("Zurücksetzen", 200, 30);
|
||||
resetButton.addActionListener(e -> {
|
||||
System.out.println("Reset-Button gedrückt");
|
||||
gameBoard.resetBoard(); // Zurücksetzen des Spielfelds
|
||||
//JOptionPane.showMessageDialog(this, "Spielfeld zurückgesetzt!", "Info", JOptionPane.INFORMATION_MESSAGE);
|
||||
});
|
||||
|
||||
// "Validieren"-Button
|
||||
JButton validateButton = createButton("Validieren", 200, 30);
|
||||
validateButton.addActionListener(e -> {
|
||||
boolean isValid = gameBoard.validateCurrentBoard(); // Prüfen, ob das Spielfeld korrekt gelöst ist
|
||||
if (isValid) {
|
||||
JOptionPane.showMessageDialog(this, "Das Spielfeld ist korrekt gelöst!", "Erfolg", JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "Das Spielfeld enthält Fehler!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
controlPanel.add(resetButton);
|
||||
controlPanel.add(validateButton);
|
||||
|
||||
// Control-Panel unterhalb des Spielfelds hinzufügen
|
||||
mainPanel.add(controlPanel, BorderLayout.SOUTH);
|
||||
mainPanel.revalidate();
|
||||
mainPanel.repaint();
|
||||
}
|
||||
|
||||
/* private void loadAndShowGameBoard(String resourcePath) {
|
||||
try {
|
||||
int[][] boardData = BoardLoader.loadBoard(resourcePath);
|
||||
List<String> solutionCoordinates = HitoriSolutionLoader.loadSolution(resourcePath);
|
||||
|
||||
HitoriBoard hitoriBoard = new HitoriBoard(boardData, solutionCoordinates);
|
||||
GameBoard gameBoard = new GameBoard(hitoriBoard);
|
||||
|
||||
loadGameBoard(boardData);
|
||||
addGameControls(gameBoard);
|
||||
} catch (IOException ex) {
|
||||
JOptionPane.showMessageDialog(this, "Fehler beim Laden des Spielfelds: " + ex.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue