Klasse erweitert
parent
b14d044443
commit
cb97bd32eb
|
@ -1,10 +1,11 @@
|
||||||
package PR2.HitoriSpiel.GUI;
|
package PR2.HitoriSpiel.GUI;
|
||||||
|
|
||||||
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
||||||
|
import PR2.HitoriSpiel.Domain.HitoriSolutionLoader;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.File;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -93,8 +94,20 @@ public class StartMenu extends JFrame {
|
||||||
String resourcePath = "/persistent/Hitori_Spielfelder/" + selectedFile;
|
String resourcePath = "/persistent/Hitori_Spielfelder/" + selectedFile;
|
||||||
System.out.println("Lade Datei von Pfad: " + resourcePath);
|
System.out.println("Lade Datei von Pfad: " + resourcePath);
|
||||||
|
|
||||||
|
|
||||||
int[][] boardData = BoardLoader.loadBoard(resourcePath);
|
int[][] boardData = BoardLoader.loadBoard(resourcePath);
|
||||||
|
List<String> solutionCoordinates = HitoriSolutionLoader.loadSolution(resourcePath);
|
||||||
|
|
||||||
|
HitoriBoard hitoriBoard = new HitoriBoard(boardData, solutionCoordinates); // Stelle sicher, dass die Lösung korrekt geladen wird
|
||||||
|
GameBoard gameBoard = new GameBoard(hitoriBoard);
|
||||||
|
|
||||||
loadGameBoard(boardData);
|
loadGameBoard(boardData);
|
||||||
|
//addGameControls(gameBoard);
|
||||||
|
|
||||||
|
System.out.println("Verfügbare Spielfelder: " + boardFileNames);
|
||||||
|
System.out.println("Ausgewählte Datei: " + selectedFile);
|
||||||
|
System.out.println("Lade Datei von Pfad: " + resourcePath);
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.err.println("Fehler beim Laden der Datei: " + ex.getMessage());
|
System.err.println("Fehler beim Laden der Datei: " + ex.getMessage());
|
||||||
|
@ -121,6 +134,14 @@ public class StartMenu extends JFrame {
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*private void loadGameBoard(GameBoard gameBoard) {
|
||||||
|
mainPanel.removeAll();
|
||||||
|
mainPanel.setLayout(new BorderLayout());
|
||||||
|
mainPanel.add(gameBoard, BorderLayout.CENTER);
|
||||||
|
mainPanel.revalidate();
|
||||||
|
mainPanel.repaint();
|
||||||
|
}*/
|
||||||
|
|
||||||
private void loadGameBoard(int[][] boardData) {
|
private void loadGameBoard(int[][] boardData) {
|
||||||
// Neues Panel für das Spielfeld
|
// Neues Panel für das Spielfeld
|
||||||
mainPanel.removeAll();
|
mainPanel.removeAll();
|
||||||
|
@ -130,4 +151,53 @@ public class StartMenu extends JFrame {
|
||||||
mainPanel.repaint();
|
mainPanel.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addGameControls(GameBoard gameBoard) {
|
||||||
|
JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); // Buttons zentriert anordnen
|
||||||
|
|
||||||
|
// "Zurücksetzen"-Button
|
||||||
|
JButton resetButton = new JButton("Zurücksetzen");
|
||||||
|
resetButton.addActionListener(e -> {
|
||||||
|
gameBoard.resetBoard(); // Zurücksetzen des Spielfelds
|
||||||
|
JOptionPane.showMessageDialog(this, "Spielfeld zurückgesetzt!", "Info", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
});
|
||||||
|
|
||||||
|
// "Validieren"-Button
|
||||||
|
JButton validateButton = new JButton("Validieren");
|
||||||
|
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