Fassade-Klassen verschoben
parent
30f11647bb
commit
5f41bda301
|
@ -2,7 +2,6 @@ package PR2.HitoriSpiel.Fassade;
|
||||||
|
|
||||||
import PR2.HitoriSpiel.Domain.Action;
|
import PR2.HitoriSpiel.Domain.Action;
|
||||||
import PR2.HitoriSpiel.Domain.HitoriValidator;
|
import PR2.HitoriSpiel.Domain.HitoriValidator;
|
||||||
import PR2.HitoriSpiel.Domain.StateManager;
|
|
||||||
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
||||||
import PR2.HitoriSpiel.Domain.HitoriCell;
|
import PR2.HitoriSpiel.Domain.HitoriCell;
|
||||||
import PR2.HitoriSpiel.GUI.PauseMenu;
|
import PR2.HitoriSpiel.GUI.PauseMenu;
|
||||||
|
@ -356,4 +355,5 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
package PR2.HitoriSpiel.Domain;
|
package PR2.HitoriSpiel.Fassade;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.Domain.Action;
|
||||||
|
import PR2.HitoriSpiel.Domain.StateFileManager;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
|
@ -2,11 +2,8 @@ package PR2.HitoriSpiel.GUI;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Enumeration;
|
import java.util.jar.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.jar.JarEntry;
|
|
||||||
import java.util.jar.JarFile;
|
|
||||||
|
|
||||||
public class BoardLoader {
|
public class BoardLoader {
|
||||||
|
|
||||||
|
@ -78,7 +75,7 @@ public class BoardLoader {
|
||||||
File[] files = directory.listFiles();
|
File[] files = directory.listFiles();
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (file.isFile() && file.getName().endsWith(".csv")) {
|
if (file.isFile() && file.getName().contains("_") && file.getName().endsWith(".csv")) {
|
||||||
boardFiles.add(file.getName());
|
boardFiles.add(file.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +97,24 @@ public class BoardLoader {
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Unbekanntes Protokoll: " + resource.getProtocol());
|
throw new IOException("Unbekanntes Protokoll: " + resource.getProtocol());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sortiere die Dateien nach Schwierigkeitsgrad und Größe
|
||||||
|
boardFiles.sort((a, b) -> {
|
||||||
|
// 1. Schwierigkeitsgrad
|
||||||
|
boolean aIsLeicht = a.contains("leicht");
|
||||||
|
boolean bIsLeicht = b.contains("leicht");
|
||||||
|
boolean aIsMedium = a.contains("medium");
|
||||||
|
boolean bIsMedium = b.contains("medium");
|
||||||
|
|
||||||
|
if (aIsLeicht && bIsMedium) return -1;
|
||||||
|
if (aIsMedium && bIsLeicht) return 1;
|
||||||
|
|
||||||
|
// 2. Größe (z. B. 8x8, 10x10)
|
||||||
|
int sizeA = extractSize(a);
|
||||||
|
int sizeB = extractSize(b);
|
||||||
|
return Integer.compare(sizeA, sizeB);
|
||||||
|
});
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Fehler beim Laden der Spielfelder: " + e.getMessage());
|
System.err.println("Fehler beim Laden der Spielfelder: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -160,4 +175,14 @@ public class BoardLoader {
|
||||||
return rows.toArray(new int[0][0]);
|
return rows.toArray(new int[0][0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Hilfsmethode zum Extrahieren der Größe aus dem Dateinamen
|
||||||
|
private static int extractSize(String fileName) {
|
||||||
|
try {
|
||||||
|
String sizePart = fileName.split("_")[0].replaceAll("\\D", ""); // Entfernt Nicht-Ziffern
|
||||||
|
return Integer.parseInt(sizePart);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Integer.MAX_VALUE; // Fehlerhafte Dateinamen landen am Ende
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package PR2.HitoriSpiel.GUI;
|
package PR2.HitoriSpiel.GUI;
|
||||||
|
|
||||||
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
||||||
import PR2.HitoriSpiel.Fassade.HitoriSolutionLoader;
|
|
||||||
import PR2.HitoriSpiel.Fassade.GameBoard;
|
import PR2.HitoriSpiel.Fassade.GameBoard;
|
||||||
|
import PR2.HitoriSpiel.Fassade.HitoriSolutionLoader;
|
||||||
import PR2.HitoriSpiel.Fassade.Setup;
|
import PR2.HitoriSpiel.Fassade.Setup;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -118,24 +118,13 @@ public class StartMenu extends JPanel {
|
||||||
new HighscoreDialog((JFrame) SwingUtilities.getWindowAncestor(this), boardNames).setVisible(true);
|
new HighscoreDialog((JFrame) SwingUtilities.getWindowAncestor(this), boardNames).setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Hilfsmethoden
|
|
||||||
private void loadGameBoard(GameBoard gameBoard, List<String> solutionCoordinates) {
|
|
||||||
removeAll();
|
|
||||||
setLayout(new BorderLayout());
|
|
||||||
add(gameBoard, BorderLayout.CENTER);
|
|
||||||
revalidate();
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadAndDisplayBoard(String selectedFile) {
|
private void loadAndDisplayBoard(String selectedFile) {
|
||||||
try {
|
try {
|
||||||
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 = loadBoard(resourcePath);
|
int[][] boardData = loadBoard(resourcePath);
|
||||||
List<String> solutionCoordinates = HitoriSolutionLoader.loadSolution(resourcePath);
|
java.util.List<String> solutionCoordinates = HitoriSolutionLoader.loadSolution(resourcePath);
|
||||||
|
|
||||||
HitoriBoard hitoriBoard = new HitoriBoard(boardData, solutionCoordinates, selectedFile); // Stelle sicher, dass die Lösung korrekt geladen wird
|
HitoriBoard hitoriBoard = new HitoriBoard(boardData, solutionCoordinates, selectedFile); // Stelle sicher, dass die Lösung korrekt geladen wird
|
||||||
GameBoard gameBoard = new GameBoard(hitoriBoard);
|
GameBoard gameBoard = new GameBoard(hitoriBoard);
|
||||||
|
@ -148,4 +137,17 @@ public class StartMenu extends JPanel {
|
||||||
JOptionPane.showMessageDialog(this, "Fehler beim Laden des Spielfelds: " + e.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(this, "Fehler beim Laden des Spielfelds: " + e.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hilfsmethoden
|
||||||
|
private void loadGameBoard(GameBoard gameBoard, java.util.List<String> solutionCoordinates) {
|
||||||
|
removeAll();
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
add(gameBoard, BorderLayout.CENTER);
|
||||||
|
revalidate();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package PR2.HitoriSpiel.Main;
|
package PR2.HitoriSpiel.Main;
|
||||||
|
|
||||||
import PR2.HitoriSpiel.GUI.StartMenu;
|
import PR2.HitoriSpiel.GUI.StartMenu;
|
||||||
import PR2.HitoriSpiel.Domain.StateManager;
|
import PR2.HitoriSpiel.Fassade.StateManager;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
9,6,10,8,5,3,10,2,5,8
|
9,6,10,8,5,3,10,2,5,8
|
||||||
9,10,2,2,4,7,9,8,5,7
|
9,10,2,2,4,7,9,8,5,7
|
||||||
|
|
||||||
// Lösung (schwarze Felder)
|
//Lösung (schwarze Felder)
|
||||||
1,1
|
1,1
|
||||||
1,3
|
1,3
|
||||||
1,6
|
1,6
|
||||||
|
|
Can't render this file because it has a wrong number of fields in line 12.
|
|
@ -3,7 +3,7 @@
|
||||||
1,3,4,2
|
1,3,4,2
|
||||||
3,4,3,2
|
3,4,3,2
|
||||||
|
|
||||||
//Lösung (schwarze Felder)
|
//Lösung
|
||||||
1,2
|
1,2
|
||||||
2,4
|
2,4
|
||||||
3,2
|
3,2
|
||||||
|
|
|
|
@ -7,7 +7,7 @@
|
||||||
8,1,3,3,6,4,2,6
|
8,1,3,3,6,4,2,6
|
||||||
5,3,6,4,3,4,8,2
|
5,3,6,4,3,4,8,2
|
||||||
|
|
||||||
// Lösung (schwarze Felder)
|
//Lösung (schwarze Felder)
|
||||||
1,1
|
1,1
|
||||||
1,8
|
1,8
|
||||||
2,2
|
2,2
|
||||||
|
|
|
Loading…
Reference in New Issue