feature(facade): Facade hinzugefügt
Facade als Anlaufpunkt für das Backend implementiert, um Trennung zu gewährleistenpull/3/head
parent
92bc8247e4
commit
cabd4db873
|
@ -1,4 +1,101 @@
|
|||
package de.deversmann.facade;
|
||||
|
||||
import de.deversmann.domain.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class Facade {
|
||||
|
||||
private final CSVReader csvReader;
|
||||
private final HighscoreManager highscoreManager;
|
||||
private final Zeiterfassung zeiterfassung;
|
||||
|
||||
private PuzzleData currentPuzzleData;
|
||||
private String currentPuzzleName;
|
||||
private int currentErrorCount = 0;
|
||||
|
||||
public Facade() {
|
||||
this.csvReader = new CSVReader();
|
||||
this.highscoreManager = new HighscoreManager();
|
||||
this.zeiterfassung = new Zeiterfassung();
|
||||
}
|
||||
|
||||
public void ladeSpielfeld(String csvPfad) throws IOException {
|
||||
this.currentPuzzleData = csvReader.readPuzzleWithSolution(csvPfad);
|
||||
this.currentPuzzleName = csvPfad;
|
||||
this.currentErrorCount = 0;
|
||||
|
||||
zeiterfassung.stop();
|
||||
zeiterfassung.start();
|
||||
System.out.println("Neues Spielfeld geladen, Timer + Fehler=0");
|
||||
}
|
||||
|
||||
public long stopZeiterfassung() {
|
||||
zeiterfassung.stop();
|
||||
return zeiterfassung.getElapsedTimeInSeconds();
|
||||
}
|
||||
|
||||
public long getElapsedTimeSoFar() {
|
||||
return zeiterfassung.getElapsedTimeInSeconds();
|
||||
}
|
||||
|
||||
public int[][] getAktuellesPuzzle() {
|
||||
return (currentPuzzleData != null) ? currentPuzzleData.getPuzzle() : null;
|
||||
}
|
||||
|
||||
public List<int[]> getLoesungsKoordinaten() {
|
||||
return (currentPuzzleData != null) ? currentPuzzleData.getSolutionCoordinates() : null;
|
||||
}
|
||||
|
||||
// Fehler-Tracking
|
||||
public void incrementErrorCount() {
|
||||
currentErrorCount++;
|
||||
}
|
||||
|
||||
public int getCurrentErrorCount() {
|
||||
return currentErrorCount;
|
||||
}
|
||||
|
||||
// Highscore
|
||||
public void addHighscoreForCurrentPuzzle(String playerName, long timeSeconds, int errorCount) {
|
||||
if (currentPuzzleName != null && !currentPuzzleName.isEmpty()) {
|
||||
highscoreManager.addHighscore(currentPuzzleName, playerName, timeSeconds, errorCount);
|
||||
}
|
||||
}
|
||||
|
||||
public List<HighscoreEntry> getHighscoresForCurrentPuzzle() {
|
||||
if (currentPuzzleName == null) {
|
||||
return List.of();
|
||||
}
|
||||
return highscoreManager.getHighscores(currentPuzzleName);
|
||||
}
|
||||
|
||||
public double getAverageTimeForCurrentPuzzle() {
|
||||
if (currentPuzzleName == null) {
|
||||
return -1;
|
||||
}
|
||||
return highscoreManager.getAverageTime(currentPuzzleName);
|
||||
}
|
||||
|
||||
public String getCurrentPuzzleName() {
|
||||
return currentPuzzleName;
|
||||
}
|
||||
|
||||
public void saveCurrentPuzzleHighscoreToFile() throws IOException {
|
||||
if (currentPuzzleName == null) return;
|
||||
String base = currentPuzzleName.replaceAll(".*/", "");
|
||||
String shortName = base.replace(".csv", "") + "_highscore.txt";
|
||||
highscoreManager.saveSinglePuzzle(currentPuzzleName, shortName);
|
||||
System.out.println("Highscore zu " + base + " in " + shortName + " gespeichert.");
|
||||
}
|
||||
|
||||
|
||||
public void loadCurrentPuzzleHighscoreFromFile() throws IOException {
|
||||
if (currentPuzzleName == null) return;
|
||||
String base = currentPuzzleName.replaceAll(".*/", "");
|
||||
String shortName = base.replace(".csv", "") + "_highscore.txt";
|
||||
highscoreManager.loadSinglePuzzle(currentPuzzleName, shortName);
|
||||
System.out.println("Highscore zu " + base + " aus " + shortName + " geladen (falls existiert).");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue