Compare commits
3 Commits
b07fcb0ff5
...
8f7d815eb5
Author | SHA1 | Date |
---|---|---|
|
8f7d815eb5 | |
|
a4c98bc5d9 | |
|
24100d209b |
|
@ -9,8 +9,10 @@ import java.util.List;
|
||||||
public class HitoriBoard {
|
public class HitoriBoard {
|
||||||
private final HitoriCell[][] board;
|
private final HitoriCell[][] board;
|
||||||
private final List<String> solutionCoordinates;
|
private final List<String> solutionCoordinates;
|
||||||
|
private int[][] originalBoardData;
|
||||||
|
|
||||||
public HitoriBoard(int[][] numbers, List<String> solutionCoordinates) {
|
public HitoriBoard(int[][] numbers, List<String> solutionCoordinates) {
|
||||||
|
this.originalBoardData = numbers; // Oginaldaten speichern
|
||||||
this.board = new HitoriCell[numbers.length][numbers[0].length];
|
this.board = new HitoriCell[numbers.length][numbers[0].length];
|
||||||
this.solutionCoordinates = solutionCoordinates;
|
this.solutionCoordinates = solutionCoordinates;
|
||||||
initializeBoard(numbers);
|
initializeBoard(numbers);
|
||||||
|
@ -19,7 +21,7 @@ public class HitoriBoard {
|
||||||
public List<String> getSolutionCoordinates() {
|
public List<String> getSolutionCoordinates() {
|
||||||
return solutionCoordinates;
|
return solutionCoordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HitoriCell[][] getBoard() {
|
public HitoriCell[][] getBoard() {
|
||||||
return board;
|
return board;
|
||||||
}
|
}
|
||||||
|
@ -37,18 +39,19 @@ public class HitoriBoard {
|
||||||
return board[row][col];
|
return board[row][col];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize(){
|
public int getSize() {
|
||||||
return board.length;
|
return board.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Board zurücksetzen zu dem Anfangszustand
|
//Board zurücksetzen zu dem Anfangszustand
|
||||||
public void resetBoard(){
|
public void resetBoard() {
|
||||||
|
//initializeBoard(originalBoardData);
|
||||||
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);
|
board[i][j].setState(HitoriCell.CellState.GRAY); // Zurücksetzen
|
||||||
|
System.out.println("Zelle Test (" + i + "," + j + ") zurückgesetzt auf GRAY");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -72,9 +72,22 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetBoard() {
|
public void resetBoard() {
|
||||||
board.resetBoard(); // Aufruf der Methode aus HitoriBoard
|
board.resetBoard(); // Logik zurücksetzen
|
||||||
revalidate();
|
removeAll(); // Entferne alle bisherigen Komponenten (Buttons)
|
||||||
repaint();
|
setLayout(new GridLayout(board.getSize(), board.getSize()));
|
||||||
|
|
||||||
|
// Neue Buttons erstellen und hinzufügen
|
||||||
|
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);
|
||||||
|
add(button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
revalidate(); // Layout neu laden
|
||||||
|
repaint(); // Oberfläche neu zeichnen
|
||||||
|
System.out.println("Spielfeld wurde aktualisiert");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean validateCurrentBoard() {
|
public boolean validateCurrentBoard() {
|
||||||
|
|
|
@ -101,8 +101,9 @@ public class StartMenu extends JFrame {
|
||||||
HitoriBoard hitoriBoard = new HitoriBoard(boardData, solutionCoordinates); // Stelle sicher, dass die Lösung korrekt geladen wird
|
HitoriBoard hitoriBoard = new HitoriBoard(boardData, solutionCoordinates); // Stelle sicher, dass die Lösung korrekt geladen wird
|
||||||
GameBoard gameBoard = new GameBoard(hitoriBoard);
|
GameBoard gameBoard = new GameBoard(hitoriBoard);
|
||||||
|
|
||||||
loadGameBoard(boardData);
|
loadGameBoard2(gameBoard, solutionCoordinates);
|
||||||
//addGameControls(gameBoard);
|
//loadGameBoard(boardData);
|
||||||
|
addGameControls(gameBoard);
|
||||||
|
|
||||||
System.out.println("Verfügbare Spielfelder: " + boardFileNames);
|
System.out.println("Verfügbare Spielfelder: " + boardFileNames);
|
||||||
System.out.println("Ausgewählte Datei: " + selectedFile);
|
System.out.println("Ausgewählte Datei: " + selectedFile);
|
||||||
|
@ -134,13 +135,13 @@ public class StartMenu extends JFrame {
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private void loadGameBoard(GameBoard gameBoard) {
|
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);
|
||||||
mainPanel.revalidate();
|
mainPanel.revalidate();
|
||||||
mainPanel.repaint();
|
mainPanel.repaint();
|
||||||
}*/
|
}
|
||||||
|
|
||||||
private void loadGameBoard(int[][] boardData) {
|
private void loadGameBoard(int[][] boardData) {
|
||||||
// Neues Panel für das Spielfeld
|
// Neues Panel für das Spielfeld
|
||||||
|
@ -155,14 +156,15 @@ public class StartMenu extends JFrame {
|
||||||
JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); // Buttons zentriert anordnen
|
JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); // Buttons zentriert anordnen
|
||||||
|
|
||||||
// "Zurücksetzen"-Button
|
// "Zurücksetzen"-Button
|
||||||
JButton resetButton = new JButton("Zurücksetzen");
|
JButton resetButton = createButton("Zurücksetzen", 200, 30);
|
||||||
resetButton.addActionListener(e -> {
|
resetButton.addActionListener(e -> {
|
||||||
|
System.out.println("Reset-Button gedrückt");
|
||||||
gameBoard.resetBoard(); // Zurücksetzen des Spielfelds
|
gameBoard.resetBoard(); // Zurücksetzen des Spielfelds
|
||||||
JOptionPane.showMessageDialog(this, "Spielfeld zurückgesetzt!", "Info", JOptionPane.INFORMATION_MESSAGE);
|
//JOptionPane.showMessageDialog(this, "Spielfeld zurückgesetzt!", "Info", JOptionPane.INFORMATION_MESSAGE);
|
||||||
});
|
});
|
||||||
|
|
||||||
// "Validieren"-Button
|
// "Validieren"-Button
|
||||||
JButton validateButton = new JButton("Validieren");
|
JButton validateButton = createButton("Validieren", 200, 30);
|
||||||
validateButton.addActionListener(e -> {
|
validateButton.addActionListener(e -> {
|
||||||
boolean isValid = gameBoard.validateCurrentBoard(); // Prüfen, ob das Spielfeld korrekt gelöst ist
|
boolean isValid = gameBoard.validateCurrentBoard(); // Prüfen, ob das Spielfeld korrekt gelöst ist
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
|
|
Loading…
Reference in New Issue