Compare commits
No commits in common. "078d653921e8c17e1bb82dd8a149cb96803968da" and "1b64e31951e87355ed4655694da8dde40de30c73" have entirely different histories.
078d653921
...
1b64e31951
|
|
@ -49,6 +49,7 @@ 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,4 +34,5 @@ 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", 150, 30);
|
JButton resetButton = createButton("Zurücksetzen", 200, 30);
|
||||||
resetButton.addActionListener(e -> {
|
resetButton.addActionListener(e -> {
|
||||||
saveStateForUndo();
|
saveStateForUndo();
|
||||||
resetBoard();
|
resetBoard();
|
||||||
refreshBoard();
|
refreshBoard();
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton undoButton = createButton("Undo", 80, 30);
|
JButton undoButton = createButton("Undo", 200, 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", 80, 30);
|
JButton redoButton = createButton("Redo", 200, 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", 100, 30);
|
JButton validateButton = createButton("Validieren", 200, 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", 100, 30);
|
JButton pauseButton = createButton("Pause", 200, 30);
|
||||||
pauseButton.addActionListener(e -> {
|
pauseButton.addActionListener(e -> {
|
||||||
stopTimer();
|
stopTimer();
|
||||||
showPauseMenu();
|
showPauseMenu();
|
||||||
|
|
@ -120,31 +120,28 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetBoard() {
|
public void resetBoard() {
|
||||||
// Spiellogik zurücksetzen
|
// Spielfeldlogik zurücksetzen
|
||||||
|
//stopTimer();
|
||||||
|
//startTimer(); // Timer neu starten
|
||||||
board.resetBoard();
|
board.resetBoard();
|
||||||
|
removeAll();
|
||||||
|
add(timerLabel, BorderLayout.NORTH);
|
||||||
|
|
||||||
// Spielfeld (CENTER) entfernen und neu erstellen
|
JPanel gamePanel = new JPanel(new GridLayout(board.getSize(), board.getSize()));
|
||||||
if (getLayout() instanceof BorderLayout) {
|
for (int i = 0; i < board.getSize(); i++) {
|
||||||
BorderLayout layout = (BorderLayout) getLayout();
|
for (int j = 0; j < board.getSize(); j++) {
|
||||||
|
HitoriCell cell = board.getCell(i, j);
|
||||||
// Komponente im CENTER entfernen
|
JButton button = createCellButton(cell, i, j);
|
||||||
Component centerComponent = layout.getLayoutComponent(BorderLayout.CENTER);
|
gamePanel.add(button);
|
||||||
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);
|
||||||
|
|
||||||
// Oberfläche aktualisieren
|
// Kontroll-Buttons unten behalten
|
||||||
|
JPanel controlPanel = createControlPanel();
|
||||||
|
add(controlPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
// Oberfläche neu laden
|
||||||
revalidate();
|
revalidate();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
@ -244,8 +241,19 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshBoard() {
|
private void refreshBoard() {
|
||||||
remove(1); // Entferne das aktuelle Spielfeld im CENTER
|
removeAll();
|
||||||
add(createGamePanel(), BorderLayout.CENTER); // Füge das neue Spielfeld hinzu
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add(gamePanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JPanel controlPanel = createControlPanel();
|
||||||
|
add(controlPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
revalidate();
|
revalidate();
|
||||||
repaint();
|
repaint();
|
||||||
|
|
@ -255,17 +263,4 @@ 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,7 +5,6 @@ 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;
|
||||||
|
|
@ -69,8 +68,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 == null || boardFileNames.isEmpty()) {
|
if (boardFileNames.isEmpty()) {
|
||||||
JOptionPane.showMessageDialog(this, "Keine Spielfelder gefunden.", "Fehler", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(this, "Keine Spielfelder gefunden.", "Information", JOptionPane.INFORMATION_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,23 +91,74 @@ 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) {
|
||||||
// Lade das ausgewählte Spielfeld
|
try {
|
||||||
System.out.println("Ich bin drin.");
|
String resourcePath = "/persistent/Hitori_Spielfelder/" + selectedFile;
|
||||||
loadAndDisplayBoard(selectedFile);
|
System.out.println("Lade Datei von Pfad: " + 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
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -124,7 +174,7 @@ public class StartMenu extends JFrame {
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadGameBoard(GameBoard gameBoard, List<String> solutionCoordinates) {
|
private void loadGameBoard2(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);
|
||||||
|
|
@ -132,25 +182,13 @@ public class StartMenu extends JFrame {
|
||||||
mainPanel.repaint();
|
mainPanel.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadAndDisplayBoard(String selectedFile) {
|
private void loadGameBoard(int[][] boardData) {
|
||||||
try {
|
// Neues Panel für das Spielfeld
|
||||||
String resourcePath = "/persistent/Hitori_Spielfelder/" + selectedFile;
|
mainPanel.removeAll();
|
||||||
System.out.println("Lade Datei von Pfad: " + resourcePath);
|
mainPanel.setLayout(new BorderLayout());
|
||||||
|
mainPanel.add(new GameBoard(new HitoriBoard(boardData, List.of())), BorderLayout.CENTER);
|
||||||
int[][] boardData = loadBoard(resourcePath);
|
mainPanel.revalidate();
|
||||||
List<String> solutionCoordinates = HitoriSolutionLoader.loadSolution(resourcePath);
|
mainPanel.repaint();
|
||||||
|
|
||||||
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,7 +5,6 @@ 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