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 j = 0; j < board[i].length; j++) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -64,14 +64,14 @@ public class GameBoard extends JPanel {
|
|||
private JPanel createControlPanel() {
|
||||
JPanel controlPanel = new JPanel();
|
||||
|
||||
JButton resetButton = createButton("Zurücksetzen", 150, 30);
|
||||
JButton resetButton = createButton("Zurücksetzen", 200, 30);
|
||||
resetButton.addActionListener(e -> {
|
||||
saveStateForUndo();
|
||||
resetBoard();
|
||||
refreshBoard();
|
||||
});
|
||||
|
||||
JButton undoButton = createButton("Undo", 80, 30);
|
||||
JButton undoButton = createButton("Undo", 200, 30);
|
||||
undoButton.addActionListener(e -> {
|
||||
int[][] previousState = stateManager.undo(board.getNumbers());
|
||||
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 -> {
|
||||
int[][] nextState = stateManager.redo(board.getNumbers());
|
||||
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 -> {
|
||||
if (validateCurrentBoard()) {
|
||||
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 -> {
|
||||
stopTimer();
|
||||
showPauseMenu();
|
||||
|
@ -120,31 +120,28 @@ public class GameBoard extends JPanel {
|
|||
}
|
||||
|
||||
public void resetBoard() {
|
||||
// Spiellogik zurücksetzen
|
||||
// Spielfeldlogik zurücksetzen
|
||||
//stopTimer();
|
||||
//startTimer(); // Timer neu starten
|
||||
board.resetBoard();
|
||||
removeAll();
|
||||
add(timerLabel, BorderLayout.NORTH);
|
||||
|
||||
// Spielfeld (CENTER) entfernen und neu erstellen
|
||||
if (getLayout() instanceof BorderLayout) {
|
||||
BorderLayout layout = (BorderLayout) getLayout();
|
||||
|
||||
// Komponente im CENTER entfernen
|
||||
Component centerComponent = layout.getLayoutComponent(BorderLayout.CENTER);
|
||||
if (centerComponent != null) {
|
||||
remove(centerComponent);
|
||||
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);
|
||||
}
|
||||
|
||||
// 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();
|
||||
repaint();
|
||||
}
|
||||
|
@ -244,8 +241,19 @@ public class GameBoard extends JPanel {
|
|||
}
|
||||
|
||||
private void refreshBoard() {
|
||||
remove(1); // Entferne das aktuelle Spielfeld im CENTER
|
||||
add(createGamePanel(), BorderLayout.CENTER); // Füge das neue Spielfeld hinzu
|
||||
removeAll();
|
||||
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();
|
||||
repaint();
|
||||
|
@ -255,17 +263,4 @@ public class GameBoard extends JPanel {
|
|||
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 java.awt.*;
|
||||
import javax.swing.JPanel;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
@ -69,8 +68,8 @@ public class StartMenu extends JFrame {
|
|||
List<String> boardFileNames = BoardLoader.loadBoardsAsList();
|
||||
System.out.println("Verfügbare Spielfelder: " + boardFileNames);
|
||||
|
||||
if (boardFileNames == null || boardFileNames.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "Keine Spielfelder gefunden.", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
if (boardFileNames.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "Keine Spielfelder gefunden.", "Information", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -92,23 +91,74 @@ public class StartMenu extends JFrame {
|
|||
if (option == JOptionPane.OK_OPTION) {
|
||||
String selectedFile = (String) boardSelector.getSelectedItem();
|
||||
System.out.println("Ausgewählte Datei: " + selectedFile);
|
||||
|
||||
if (selectedFile != null) {
|
||||
// Lade das ausgewählte Spielfeld
|
||||
System.out.println("Ich bin drin.");
|
||||
loadAndDisplayBoard(selectedFile);
|
||||
try {
|
||||
String resourcePath = "/persistent/Hitori_Spielfelder/" + 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() {
|
||||
// Lade alle verfügbaren Spielfeld-Dateien
|
||||
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);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
private void loadGameBoard(GameBoard gameBoard, List<String> solutionCoordinates) {
|
||||
private void loadGameBoard2(GameBoard gameBoard,List<String> solutionCoordinates) {
|
||||
mainPanel.removeAll();
|
||||
mainPanel.setLayout(new BorderLayout());
|
||||
mainPanel.add(gameBoard, BorderLayout.CENTER);
|
||||
|
@ -132,25 +182,13 @@ public class StartMenu extends JFrame {
|
|||
mainPanel.repaint();
|
||||
}
|
||||
|
||||
private void loadAndDisplayBoard(String selectedFile) {
|
||||
try {
|
||||
String resourcePath = "/persistent/Hitori_Spielfelder/" + 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);
|
||||
//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);
|
||||
}
|
||||
private void loadGameBoard(int[][] boardData) {
|
||||
// Neues Panel für das Spielfeld
|
||||
mainPanel.removeAll();
|
||||
mainPanel.setLayout(new BorderLayout());
|
||||
mainPanel.add(new GameBoard(new HitoriBoard(boardData, List.of())), BorderLayout.CENTER);
|
||||
mainPanel.revalidate();
|
||||
mainPanel.repaint();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import PR2.HitoriSpiel.GUI.StartMenu;
|
|||
import javax.swing.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Einstiegspunkt des Hitori-Spiels. Initialisiert die GUI und startet das Programm.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue