Compare commits
5 Commits
1b64e31951
...
078d653921
Author | SHA1 | Date |
---|---|---|
|
078d653921 | |
|
6462424563 | |
|
152b50fc69 | |
|
43c73b0289 | |
|
3b6e3a45a7 |
|
@ -49,7 +49,6 @@ public class HitoriBoard {
|
||||||
for (int i = 0; i < board.length; i++) {
|
for (int i = 0; i < board.length; i++) {
|
||||||
for (int j = 0; j < board[i].length; j++) {
|
for (int j = 0; j < board[i].length; j++) {
|
||||||
board[i][j].setState(HitoriCell.CellState.GRAY); // Zurücksetzen
|
board[i][j].setState(HitoriCell.CellState.GRAY); // Zurücksetzen
|
||||||
System.out.println("Zelle Test (" + i + "," + j + ") zurückgesetzt auf GRAY");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,5 +34,4 @@ public class HitoriSolutionLoader {
|
||||||
|
|
||||||
return solutionCoordinates;
|
return solutionCoordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -64,14 +64,14 @@ public class GameBoard extends JPanel {
|
||||||
private JPanel createControlPanel() {
|
private JPanel createControlPanel() {
|
||||||
JPanel controlPanel = new JPanel();
|
JPanel controlPanel = new JPanel();
|
||||||
|
|
||||||
JButton resetButton = createButton("Zurücksetzen", 200, 30);
|
JButton resetButton = createButton("Zurücksetzen", 150, 30);
|
||||||
resetButton.addActionListener(e -> {
|
resetButton.addActionListener(e -> {
|
||||||
saveStateForUndo();
|
saveStateForUndo();
|
||||||
resetBoard();
|
resetBoard();
|
||||||
refreshBoard();
|
refreshBoard();
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton undoButton = createButton("Undo", 200, 30);
|
JButton undoButton = createButton("Undo", 80, 30);
|
||||||
undoButton.addActionListener(e -> {
|
undoButton.addActionListener(e -> {
|
||||||
int[][] previousState = stateManager.undo(board.getNumbers());
|
int[][] previousState = stateManager.undo(board.getNumbers());
|
||||||
if (previousState != null) {
|
if (previousState != null) {
|
||||||
|
@ -82,7 +82,7 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton redoButton = createButton("Redo", 200, 30);
|
JButton redoButton = createButton("Redo", 80, 30);
|
||||||
redoButton.addActionListener(e -> {
|
redoButton.addActionListener(e -> {
|
||||||
int[][] nextState = stateManager.redo(board.getNumbers());
|
int[][] nextState = stateManager.redo(board.getNumbers());
|
||||||
if (nextState != null) {
|
if (nextState != null) {
|
||||||
|
@ -93,7 +93,7 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton validateButton = createButton("Validieren", 200, 30);
|
JButton validateButton = createButton("Validieren", 100, 30);
|
||||||
validateButton.addActionListener(e -> {
|
validateButton.addActionListener(e -> {
|
||||||
if (validateCurrentBoard()) {
|
if (validateCurrentBoard()) {
|
||||||
stopTimer();
|
stopTimer();
|
||||||
|
@ -103,7 +103,7 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton pauseButton = createButton("Pause", 200, 30);
|
JButton pauseButton = createButton("Pause", 100, 30);
|
||||||
pauseButton.addActionListener(e -> {
|
pauseButton.addActionListener(e -> {
|
||||||
stopTimer();
|
stopTimer();
|
||||||
showPauseMenu();
|
showPauseMenu();
|
||||||
|
@ -120,28 +120,31 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetBoard() {
|
public void resetBoard() {
|
||||||
// Spielfeldlogik zurücksetzen
|
// Spiellogik zurücksetzen
|
||||||
//stopTimer();
|
|
||||||
//startTimer(); // Timer neu starten
|
|
||||||
board.resetBoard();
|
board.resetBoard();
|
||||||
removeAll();
|
|
||||||
add(timerLabel, BorderLayout.NORTH);
|
|
||||||
|
|
||||||
JPanel gamePanel = new JPanel(new GridLayout(board.getSize(), board.getSize()));
|
// Spielfeld (CENTER) entfernen und neu erstellen
|
||||||
for (int i = 0; i < board.getSize(); i++) {
|
if (getLayout() instanceof BorderLayout) {
|
||||||
for (int j = 0; j < board.getSize(); j++) {
|
BorderLayout layout = (BorderLayout) getLayout();
|
||||||
HitoriCell cell = board.getCell(i, j);
|
|
||||||
JButton button = createCellButton(cell, i, j);
|
// Komponente im CENTER entfernen
|
||||||
gamePanel.add(button);
|
Component centerComponent = layout.getLayoutComponent(BorderLayout.CENTER);
|
||||||
|
if (centerComponent != null) {
|
||||||
|
remove(centerComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Neues Spielfeld hinzufügen
|
||||||
|
add(createGamePanel(), BorderLayout.CENTER);
|
||||||
|
|
||||||
|
// Kontroll-Buttons (SOUTH) entfernen und neu hinzufügen
|
||||||
|
Component southComponent = layout.getLayoutComponent(BorderLayout.SOUTH);
|
||||||
|
if (southComponent != null) {
|
||||||
|
remove(southComponent);
|
||||||
|
}
|
||||||
|
add(createControlPanel(), BorderLayout.SOUTH);
|
||||||
}
|
}
|
||||||
add(gamePanel, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
// Kontroll-Buttons unten behalten
|
// Oberfläche aktualisieren
|
||||||
JPanel controlPanel = createControlPanel();
|
|
||||||
add(controlPanel, BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
// Oberfläche neu laden
|
|
||||||
revalidate();
|
revalidate();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
@ -241,19 +244,8 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshBoard() {
|
private void refreshBoard() {
|
||||||
removeAll();
|
remove(1); // Entferne das aktuelle Spielfeld im CENTER
|
||||||
JPanel gamePanel = new JPanel(new GridLayout(board.getSize(), board.getSize()));
|
add(createGamePanel(), BorderLayout.CENTER); // Füge das neue Spielfeld hinzu
|
||||||
for (int i = 0; i < board.getSize(); i++) {
|
|
||||||
for (int j = 0; j < board.getSize(); j++) {
|
|
||||||
HitoriCell cell = board.getCell(i, j);
|
|
||||||
JButton button = createCellButton(cell, i, j);
|
|
||||||
gamePanel.add(button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add(gamePanel, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
JPanel controlPanel = createControlPanel();
|
|
||||||
add(controlPanel, BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
revalidate();
|
revalidate();
|
||||||
repaint();
|
repaint();
|
||||||
|
@ -263,4 +255,17 @@ public class GameBoard extends JPanel {
|
||||||
stateManager.saveState(board.getNumbers());
|
stateManager.saveState(board.getNumbers());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JPanel createGamePanel() {
|
||||||
|
JPanel gamePanel = new JPanel(new GridLayout(board.getSize(), board.getSize()));
|
||||||
|
for (int i = 0; i < board.getSize(); i++) {
|
||||||
|
for (int j = 0; j < board.getSize(); j++) {
|
||||||
|
HitoriCell cell = board.getCell(i, j);
|
||||||
|
JButton button = createCellButton(cell, i, j);
|
||||||
|
gamePanel.add(button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("Spielpanel erstellt mit " + (board.getSize() * board.getSize()) + " Buttons.");
|
||||||
|
return gamePanel;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import PR2.HitoriSpiel.Domain.HitoriSolutionLoader;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import javax.swing.JPanel;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -68,8 +69,8 @@ public class StartMenu extends JFrame {
|
||||||
List<String> boardFileNames = BoardLoader.loadBoardsAsList();
|
List<String> boardFileNames = BoardLoader.loadBoardsAsList();
|
||||||
System.out.println("Verfügbare Spielfelder: " + boardFileNames);
|
System.out.println("Verfügbare Spielfelder: " + boardFileNames);
|
||||||
|
|
||||||
if (boardFileNames.isEmpty()) {
|
if (boardFileNames == null || boardFileNames.isEmpty()) {
|
||||||
JOptionPane.showMessageDialog(this, "Keine Spielfelder gefunden.", "Information", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(this, "Keine Spielfelder gefunden.", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,74 +92,23 @@ public class StartMenu extends JFrame {
|
||||||
if (option == JOptionPane.OK_OPTION) {
|
if (option == JOptionPane.OK_OPTION) {
|
||||||
String selectedFile = (String) boardSelector.getSelectedItem();
|
String selectedFile = (String) boardSelector.getSelectedItem();
|
||||||
System.out.println("Ausgewählte Datei: " + selectedFile);
|
System.out.println("Ausgewählte Datei: " + selectedFile);
|
||||||
|
|
||||||
if (selectedFile != null) {
|
if (selectedFile != null) {
|
||||||
try {
|
// Lade das ausgewählte Spielfeld
|
||||||
String resourcePath = "/persistent/Hitori_Spielfelder/" + selectedFile;
|
System.out.println("Ich bin drin.");
|
||||||
System.out.println("Lade Datei von Pfad: " + resourcePath);
|
loadAndDisplayBoard(selectedFile);
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
GameBoard gameBoard = new GameBoard(hitoriBoard);
|
|
||||||
|
|
||||||
loadGameBoard2(gameBoard, solutionCoordinates);
|
|
||||||
//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) {
|
|
||||||
System.err.println("Fehler beim Laden der Datei: " + ex.getMessage());
|
|
||||||
JOptionPane.showMessageDialog(this, "Fehler beim Laden des Spielfelds: " + ex.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void randomBoard() {
|
private void randomBoard() {
|
||||||
// Lade alle verfügbaren Spielfeld-Dateien
|
|
||||||
List<String> boardFileNames = BoardLoader.loadBoardsAsList();
|
List<String> boardFileNames = BoardLoader.loadBoardsAsList();
|
||||||
|
if (boardFileNames == null || boardFileNames.isEmpty()) {
|
||||||
// Überprüfe, ob Dateien verfügbar sind
|
|
||||||
if (boardFileNames.isEmpty()) {
|
|
||||||
JOptionPane.showMessageDialog(this, "Keine Spielfelder gefunden.", "Fehler", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(this, "Keine Spielfelder gefunden.", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wähle eine zufällige Datei
|
|
||||||
String randomFile = boardFileNames.get(new Random().nextInt(boardFileNames.size()));
|
String randomFile = boardFileNames.get(new Random().nextInt(boardFileNames.size()));
|
||||||
System.out.println("Zufällige Datei gewählt: " + randomFile);
|
System.out.println("Zufällige Datei gewählt: " + randomFile);
|
||||||
|
loadAndDisplayBoard(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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -174,7 +124,7 @@ public class StartMenu extends JFrame {
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadGameBoard2(GameBoard gameBoard,List<String> solutionCoordinates) {
|
private void loadGameBoard(GameBoard gameBoard, List<String> solutionCoordinates) {
|
||||||
mainPanel.removeAll();
|
mainPanel.removeAll();
|
||||||
mainPanel.setLayout(new BorderLayout());
|
mainPanel.setLayout(new BorderLayout());
|
||||||
mainPanel.add(gameBoard, BorderLayout.CENTER);
|
mainPanel.add(gameBoard, BorderLayout.CENTER);
|
||||||
|
@ -182,13 +132,25 @@ public class StartMenu extends JFrame {
|
||||||
mainPanel.repaint();
|
mainPanel.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadGameBoard(int[][] boardData) {
|
private void loadAndDisplayBoard(String selectedFile) {
|
||||||
// Neues Panel für das Spielfeld
|
try {
|
||||||
mainPanel.removeAll();
|
String resourcePath = "/persistent/Hitori_Spielfelder/" + selectedFile;
|
||||||
mainPanel.setLayout(new BorderLayout());
|
System.out.println("Lade Datei von Pfad: " + resourcePath);
|
||||||
mainPanel.add(new GameBoard(new HitoriBoard(boardData, List.of())), BorderLayout.CENTER);
|
|
||||||
mainPanel.revalidate();
|
int[][] boardData = loadBoard(resourcePath);
|
||||||
mainPanel.repaint();
|
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);
|
||||||
|
//GameBoard gameBoard = new GameBoard(new HitoriBoard(boardData, solutionCoordinates));
|
||||||
|
loadGameBoard(gameBoard, solutionCoordinates);
|
||||||
|
|
||||||
|
System.out.println("Ausgewählte Datei: " + selectedFile);
|
||||||
|
System.out.println("Lade Datei von Pfad: " + resourcePath);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
JOptionPane.showMessageDialog(this, "Fehler beim Laden des Spielfelds: " + e.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import PR2.HitoriSpiel.GUI.StartMenu;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Einstiegspunkt des Hitori-Spiels. Initialisiert die GUI und startet das Programm.
|
* Einstiegspunkt des Hitori-Spiels. Initialisiert die GUI und startet das Programm.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue