Compare commits
3 Commits
a866e7f2bf
...
ae5fb68bd4
Author | SHA1 | Date |
---|---|---|
|
ae5fb68bd4 | |
|
da6ffa8379 | |
|
4394a89a9c |
|
@ -0,0 +1,39 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package de.deversmann.domain;
|
||||
|
||||
|
||||
public class Zeiterfassung {
|
||||
|
||||
private long startTime;
|
||||
|
|
|
@ -1,54 +1,4 @@
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ import java.util.Random;
|
|||
public class GameView extends JFrame {
|
||||
|
||||
private final Facade facade;
|
||||
private SpielfeldGUI_2_0 spielfeldGUI;
|
||||
private SpielfeldGUI 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_2_0(1, 1);
|
||||
spielfeldGUI = new SpielfeldGUI(1, 1);
|
||||
getContentPane().add(spielfeldGUI, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.deversmann.gui;
|
|||
|
||||
import de.deversmann.facade.Facade;
|
||||
|
||||
|
||||
public class HitoriApp {
|
||||
|
||||
private Facade facade;
|
||||
|
@ -14,4 +15,4 @@ public class HitoriApp {
|
|||
GameView view = new GameView(facade);
|
||||
view.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,14 @@ import java.awt.*;
|
|||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class SpielfeldGUI_2_0 extends JPanel {
|
||||
public class SpielfeldGUI extends JPanel {
|
||||
|
||||
private JLabel[][] grid;
|
||||
private Set<String> errorCells = new HashSet<>();
|
||||
|
||||
public SpielfeldGUI_2_0(int rows, int cols) {
|
||||
public SpielfeldGUI(int rows, int cols) {
|
||||
setLayout(new GridLayout(rows, cols));
|
||||
grid = new JLabel[rows][cols];
|
||||
|
||||
|
@ -132,4 +133,4 @@ public class SpielfeldGUI_2_0 extends JPanel {
|
|||
if (grid == null) return false;
|
||||
return (r >= 0 && r < grid.length && c >= 0 && c < grid[r].length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue