Compare commits

..

No commits in common. "ae5fb68bd49105742715df12743da477ea3d5020" and "a866e7f2bfa25c94db3bbbb90bcb116f85183790" have entirely different histories.

6 changed files with 58 additions and 48 deletions

View File

@ -1,39 +0,0 @@
package de.deversmann.domain;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class CSVReader {
/**
* Liest die CSV-Datei ein und gibt die enthaltenen Werte als zweidimensionales int-Array zurück.
*
* @param csvFile Pfad zur CSV-Datei
* @return zweidimensionales Array, das die Zahlen aus der CSV enthält
* @throws IOException wenn ein Fehler beim Lesen auftritt
*/
public int[][] readCsvToIntArray(String csvFile) throws IOException {
ArrayList<int[]> rows = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {
String line;
while ((line = br.readLine()) != null) {
String[] tokens = line.split(",");
int[] row = new int[tokens.length];
for (int i = 0; i < tokens.length; i++) {
row[i] = Integer.parseInt(tokens[i].trim());
}
rows.add(row);
}
}
// ArrayList in 2D-Array umwandeln
int[][] result = new int[rows.size()][];
for (int i = 0; i < rows.size(); i++) {
result[i] = rows.get(i);
}
return result;
}
}

View File

@ -1,5 +1,6 @@
package de.deversmann.domain;
public class Zeiterfassung {
private long startTime;

View File

@ -1,4 +1,54 @@
package de.deversmann.facade;
import java.io.IOException;
import java.util.List;
public class Facade {
}
private final CSVReader csvReader;
private final HighscoreManager_2_0 highscoreManager;
private final Zeiterfassung_2_0 zeiterfassung;
// Hier speichern wir das aktuell geladene Puzzle (mit Lösung)
private PuzzleData currentPuzzleData;
public Facade() {
this.csvReader = new CSVReader();
this.highscoreManager = new HighscoreManager_2_0();
this.zeiterfassung = new Zeiterfassung_2_0();
}
public void ladeSpielfeld(String csvPfad) throws IOException {
// Liest Puzzle + Lösung aus der CSV
this.currentPuzzleData = csvReader.readPuzzleWithSolution(csvPfad);
}
public int[][] getAktuellesPuzzle() {
return (currentPuzzleData != null)
? currentPuzzleData.getPuzzle()
: null;
}
public List<int[]> getLoesungsKoordinaten() {
return (currentPuzzleData != null)
? currentPuzzleData.getSolutionCoordinates()
: null;
}
public void startZeiterfassung() {
zeiterfassung.start();
}
public long stopZeiterfassung() {
zeiterfassung.stop();
return zeiterfassung.getElapsedTimeInSeconds();
}
public void addHighscore(int score) {
highscoreManager.addHighscore(score);
}
public List<Integer> getAllHighscores() {
return highscoreManager.getHighscores();
}
}

View File

@ -11,7 +11,7 @@ import java.util.Random;
public class GameView extends JFrame {
private final Facade facade;
private SpielfeldGUI spielfeldGUI;
private SpielfeldGUI_2_0 spielfeldGUI;
private JComboBox<String> cbSpielfelder;
private JButton btnLoad;
@ -84,7 +84,7 @@ public class GameView extends JFrame {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(controlPanel, BorderLayout.NORTH);
spielfeldGUI = new SpielfeldGUI(1, 1);
spielfeldGUI = new SpielfeldGUI_2_0(1, 1);
getContentPane().add(spielfeldGUI, BorderLayout.CENTER);
}

View File

@ -2,7 +2,6 @@ package de.deversmann.gui;
import de.deversmann.facade.Facade;
public class HitoriApp {
private Facade facade;
@ -15,4 +14,4 @@ public class HitoriApp {
GameView view = new GameView(facade);
view.setVisible(true);
}
}
}

View File

@ -5,14 +5,13 @@ import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.*;
import java.util.List;
public class SpielfeldGUI extends JPanel {
public class SpielfeldGUI_2_0 extends JPanel {
private JLabel[][] grid;
private Set<String> errorCells = new HashSet<>();
public SpielfeldGUI(int rows, int cols) {
public SpielfeldGUI_2_0(int rows, int cols) {
setLayout(new GridLayout(rows, cols));
grid = new JLabel[rows][cols];
@ -133,4 +132,4 @@ public class SpielfeldGUI extends JPanel {
if (grid == null) return false;
return (r >= 0 && r < grid.length && c >= 0 && c < grid[r].length);
}
}
}