Compare commits
No commits in common. "e832fc5f6fcc0120b917bda4c702cdf8d34a1025" and "daedc2bf63ca4faa3648a7d2f4007dcc40d6c062" have entirely different histories.
e832fc5f6f
...
daedc2bf63
|
|
@ -1,83 +0,0 @@
|
||||||
7,1,2,9,12,15,8,11,11,9,11,14,13,6,3
|
|
||||||
2,3,8,1,2,11,10,9,5,8,14,3,12,13,15
|
|
||||||
4,14,13,9,4,15,9,10,12,6,5,3,11,5,12
|
|
||||||
15,9,5,6,10,15,1,15,8,3,5,4,6,2,8
|
|
||||||
5,11,7,9,15,1,4,3,8,1,9,2,10,13,2
|
|
||||||
15,15,10,3,1,14,8,12,11,1,9,8,2,7,2
|
|
||||||
10,7,7,12,9,3,15,2,5,2,10,5,1,7,4
|
|
||||||
3,8,9,14,1,6,12,4,15,2,13,11,5,10,11
|
|
||||||
8,6,7,15,11,4,5,11,2,10,3,13,8,12,9
|
|
||||||
2,2,3,3,4,13,5,6,5,11,5,15,8,9,12
|
|
||||||
2,15,15,11,13,7,6,5,3,13,8,10,5,1,11
|
|
||||||
12,5,11,13,13,2,2,8,8,4,10,9,3,2,5
|
|
||||||
1,13,8,2,1,7,11,4,9,15,4,12,9,3,10
|
|
||||||
13,10,12,5,15,3,2,7,13,14,12,12,9,11,6
|
|
||||||
7,12,4,8,14,10,13,13,7,4,2,6,15,15,11
|
|
||||||
|
|
||||||
//Lösung
|
|
||||||
1,4
|
|
||||||
1,6
|
|
||||||
1,8
|
|
||||||
1,11
|
|
||||||
2,1
|
|
||||||
2,3
|
|
||||||
2,9
|
|
||||||
2,12
|
|
||||||
2,14
|
|
||||||
3,5
|
|
||||||
3,7
|
|
||||||
3,11
|
|
||||||
3,15
|
|
||||||
4,1
|
|
||||||
4,3
|
|
||||||
4,6
|
|
||||||
4,9
|
|
||||||
4,13
|
|
||||||
5,4
|
|
||||||
5,10
|
|
||||||
5,15
|
|
||||||
6,2
|
|
||||||
6,5
|
|
||||||
6,7
|
|
||||||
6,9
|
|
||||||
6,11
|
|
||||||
6,13
|
|
||||||
7,1
|
|
||||||
7,3
|
|
||||||
7,6
|
|
||||||
7,8
|
|
||||||
7,12
|
|
||||||
7,14
|
|
||||||
8,5
|
|
||||||
8,9
|
|
||||||
8,15
|
|
||||||
9,3
|
|
||||||
9,8
|
|
||||||
9,13
|
|
||||||
10,1
|
|
||||||
10,4
|
|
||||||
10,7
|
|
||||||
10,9
|
|
||||||
10,11
|
|
||||||
11,3
|
|
||||||
11,10
|
|
||||||
11,13
|
|
||||||
11,15
|
|
||||||
12,2
|
|
||||||
12,5
|
|
||||||
12,7
|
|
||||||
12,9
|
|
||||||
12,11
|
|
||||||
12,14
|
|
||||||
13,1
|
|
||||||
13,6
|
|
||||||
13,8
|
|
||||||
13,13
|
|
||||||
14,3
|
|
||||||
14,5
|
|
||||||
14,9
|
|
||||||
14,12
|
|
||||||
15,1
|
|
||||||
15,7
|
|
||||||
15,10
|
|
||||||
15,14
|
|
||||||
|
Can't render this file because it has a wrong number of fields in line 17.
|
|
|
@ -1,75 +0,0 @@
|
||||||
package de.deversmann.domain;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class HighscoreManager {
|
|
||||||
private final Map<String, List<HighscoreEntry>> highscoreMap;
|
|
||||||
|
|
||||||
public HighscoreManager() {
|
|
||||||
highscoreMap = new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addHighscore(String spielfeld, String name, long zeit, int fehler) {
|
|
||||||
HighscoreEntry entry = new HighscoreEntry(name, zeit, fehler);
|
|
||||||
highscoreMap.computeIfAbsent(spielfeld, k -> new ArrayList<>()).add(entry);
|
|
||||||
saveHighscores();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<HighscoreEntry> getHighscores(String spielfeld) {
|
|
||||||
return highscoreMap.getOrDefault(spielfeld, new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getDurchschnittszeit(String spielfeld) {
|
|
||||||
List<HighscoreEntry> highscores = getHighscores(spielfeld);
|
|
||||||
return highscores.stream().mapToLong(HighscoreEntry::getZeit).average().orElse(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveHighscores() {
|
|
||||||
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("highscores.dat"))) {
|
|
||||||
oos.writeObject(highscoreMap);
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println("Fehler beim Speichern der Highscores: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void loadHighscores() {
|
|
||||||
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("highscores.dat"))) {
|
|
||||||
Map<String, List<HighscoreEntry>> loadedMap = (Map<String, List<HighscoreEntry>>) ois.readObject();
|
|
||||||
highscoreMap.clear();
|
|
||||||
highscoreMap.putAll(loadedMap);
|
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
|
||||||
System.err.println("Fehler beim Laden der Highscores: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class HighscoreEntry implements Serializable {
|
|
||||||
private final String name;
|
|
||||||
private final long zeit;
|
|
||||||
private final int fehler;
|
|
||||||
|
|
||||||
public HighscoreEntry(String name, long zeit, int fehler) {
|
|
||||||
this.name = name;
|
|
||||||
this.zeit = zeit;
|
|
||||||
this.fehler = fehler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getZeit() {
|
|
||||||
return zeit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getFehler() {
|
|
||||||
return fehler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return name + ": " + zeit + "ms, Fehler: " + fehler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,110 +1,4 @@
|
||||||
package de.deversmann.domain;
|
package de.deversmann.domain;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class Spielfeld {
|
public class Spielfeld {
|
||||||
|
|
||||||
private int[][] feld;
|
|
||||||
private String[][] zustand; // "grau", "schwarz", "weiß"
|
|
||||||
|
|
||||||
public Spielfeld() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ladeSpielfeld(String dateiPfad) {
|
|
||||||
try (BufferedReader br = new BufferedReader(new FileReader(dateiPfad))) {
|
|
||||||
String line;
|
|
||||||
int zeilenZaehler = 0;
|
|
||||||
|
|
||||||
|
|
||||||
while ((line = br.readLine()) != null) {
|
|
||||||
zeilenZaehler++;
|
|
||||||
}
|
|
||||||
|
|
||||||
br.close();
|
|
||||||
|
|
||||||
feld = new int[zeilenZaehler][];
|
|
||||||
zustand = new String[zeilenZaehler][];
|
|
||||||
|
|
||||||
try (BufferedReader br2 = new BufferedReader(new FileReader(dateiPfad))) {
|
|
||||||
int row = 0;
|
|
||||||
while ((line = br2.readLine()) != null) {
|
|
||||||
String[] werte = line.split(",");
|
|
||||||
feld[row] = new int[werte.length];
|
|
||||||
zustand[row] = new String[werte.length];
|
|
||||||
|
|
||||||
for (int col = 0; col < werte.length; col++) {
|
|
||||||
feld[row][col] = Integer.parseInt(werte[col]);
|
|
||||||
zustand[row][col] = "grau";
|
|
||||||
}
|
|
||||||
|
|
||||||
row++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println("Fehler beim Laden des Spielfelds: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ladeZufaelligesSpielfeld(String ordnerPfad) {
|
|
||||||
File ordner = new File(ordnerPfad);
|
|
||||||
File[] dateien = ordner.listFiles((dir, name) -> name.endsWith(".csv"));
|
|
||||||
|
|
||||||
if (dateien != null && dateien.length > 0) {
|
|
||||||
Random random = new Random();
|
|
||||||
File zufallsDatei = dateien[random.nextInt(dateien.length)];
|
|
||||||
ladeSpielfeld(zufallsDatei.getAbsolutePath());
|
|
||||||
} else {
|
|
||||||
System.err.println("Keine CSV-Dateien im Verzeichnis gefunden!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setzeZustand(int x, int y, String neuerZustand) {
|
|
||||||
if (istImBereich(x, y)) {
|
|
||||||
zustand[x][y] = neuerZustand;
|
|
||||||
} else {
|
|
||||||
System.err.println("Koordinaten außerhalb des Spielfelds!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getZustand(int x, int y) {
|
|
||||||
if (istImBereich(x, y)) {
|
|
||||||
return zustand[x][y];
|
|
||||||
} else {
|
|
||||||
System.err.println("Koordinaten außerhalb des Spielfelds!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWert(int x, int y) {
|
|
||||||
if (istImBereich(x, y)) {
|
|
||||||
return feld[x][y];
|
|
||||||
} else {
|
|
||||||
System.err.println("Koordinaten außerhalb des Spielfelds!");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reset() {
|
|
||||||
for (int i = 0; i < zustand.length; i++) {
|
|
||||||
for (int j = 0; j < zustand[i].length; j++) {
|
|
||||||
zustand[i][j] = "grau";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getBreite() {
|
|
||||||
return feld[0].length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHoehe() {
|
|
||||||
return feld.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean istImBereich(int x, int y) {
|
|
||||||
return x >= 0 && x < feld.length && y >= 0 && y < feld[0].length;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
package de.deversmann.domain;
|
|
||||||
|
|
||||||
public class Zeiterfassung {
|
|
||||||
private long startzeit;
|
|
||||||
private long endzeit;
|
|
||||||
private boolean laufen;
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
this.startzeit = System.currentTimeMillis();
|
|
||||||
this.laufen= true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
this.endzeit = System.currentTimeMillis();
|
|
||||||
this.laufen= false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getElapsedTimeMillis() {
|
|
||||||
long endTime = laufen ? System.currentTimeMillis() : endzeit;
|
|
||||||
return endTime - startzeit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reset() {
|
|
||||||
this.startzeit = 0;
|
|
||||||
this.endzeit = 0;
|
|
||||||
this.laufen = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFormattedTime() {
|
|
||||||
long elapsed = getElapsedTimeMillis();
|
|
||||||
long hours = elapsed / (3600_000);
|
|
||||||
long remainder = elapsed % 3600_000;
|
|
||||||
long minutes = remainder / 60_000;
|
|
||||||
remainder = remainder % 60_000;
|
|
||||||
long seconds = remainder / 1_000;
|
|
||||||
long millis = remainder % 1_000;
|
|
||||||
|
|
||||||
// Formatierung zu einer lesbaren Zeitangabe
|
|
||||||
return String.format("%02d:%02d:%02d.%03d", hours, minutes, seconds, millis);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package de.deversmann.gui;
|
||||||
|
|
||||||
|
public class Spielfeld {
|
||||||
|
}
|
||||||
|
|
@ -1,97 +0,0 @@
|
||||||
package de.deversmann.gui;
|
|
||||||
|
|
||||||
import de.deversmann.domain.Spielfeld;
|
|
||||||
import de.deversmann.domain.Zeiterfassung;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public class SpielfeldGUI {
|
|
||||||
|
|
||||||
private JFrame frame;
|
|
||||||
private JPanel spielfeldPanel;
|
|
||||||
private JLabel timerLabel;
|
|
||||||
private Timer guiTimer;
|
|
||||||
private Spielfeld spielfeld;
|
|
||||||
private Zeiterfassung timer;
|
|
||||||
|
|
||||||
public SpielfeldGUI() {
|
|
||||||
// Initialisiere Domain-Klassen
|
|
||||||
spielfeld = new Spielfeld();
|
|
||||||
timer = new Zeiterfassung();
|
|
||||||
|
|
||||||
// Erstelle das Hauptfenster
|
|
||||||
frame = new JFrame("Hitori Spielfeld");
|
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
frame.setSize(800, 600);
|
|
||||||
frame.setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
// Timer-Anzeige
|
|
||||||
timerLabel = new JLabel("00:00:00.000");
|
|
||||||
timerLabel.setFont(new Font("Monospaced", Font.BOLD, 16));
|
|
||||||
frame.add(timerLabel, BorderLayout.NORTH);
|
|
||||||
|
|
||||||
// Spielfeld-Panel
|
|
||||||
spielfeldPanel = new JPanel();
|
|
||||||
frame.add(spielfeldPanel, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
// Button-Panel
|
|
||||||
JPanel buttonPanel = new JPanel();
|
|
||||||
JButton selectButton = new JButton("Spielfeld auswählen");
|
|
||||||
JButton startButton = new JButton("Timer starten");
|
|
||||||
JButton stopButton = new JButton("Timer stoppen");
|
|
||||||
|
|
||||||
buttonPanel.add(selectButton);
|
|
||||||
buttonPanel.add(startButton);
|
|
||||||
buttonPanel.add(stopButton);
|
|
||||||
frame.add(buttonPanel, BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
// Aktionen für Buttons
|
|
||||||
selectButton.addActionListener(e -> ladeSpielfeldMitAuswahl());
|
|
||||||
startButton.addActionListener(e -> starteTimer());
|
|
||||||
stopButton.addActionListener(e -> stoppeTimer());
|
|
||||||
|
|
||||||
// Timer für GUI-Updates
|
|
||||||
guiTimer = new Timer(100, e -> timerLabel.setText(timer.getFormattedTime()));
|
|
||||||
|
|
||||||
// Fenster sichtbar machen
|
|
||||||
frame.setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void starteTimer() {
|
|
||||||
timer.start();
|
|
||||||
guiTimer.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stoppeTimer() {
|
|
||||||
timer.stop();
|
|
||||||
guiTimer.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ladeSpielfeldMitAuswahl() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void zeigeSpielfeld() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void feldAktion(int x, int y, JButton button) {
|
|
||||||
String aktuellerZustand = spielfeld.getZustand(x, y);
|
|
||||||
String neuerZustand = switch (aktuellerZustand) {
|
|
||||||
case "grau" -> "schwarz";
|
|
||||||
case "schwarz" -> "weiß";
|
|
||||||
default -> "grau";
|
|
||||||
};
|
|
||||||
spielfeld.setzeZustand(x, y, neuerZustand);
|
|
||||||
button.setBackground(switch (neuerZustand) {
|
|
||||||
case "schwarz" -> Color.BLACK;
|
|
||||||
case "weiß" -> Color.WHITE;
|
|
||||||
default -> Color.GRAY;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SwingUtilities.invokeLater(SpielfeldGUI::new);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue