Merge remote-tracking branch 'origin/Improvements_Vick' into Improvements_Together
# Conflicts: # Hitori/src/main/highscores/highscores.txtImprovements_Together
commit
f7a65be2c4
|
@ -15,6 +15,7 @@ public class GameBoard extends JPanel {
|
|||
private Timer timer;
|
||||
private long startTime;
|
||||
private JLabel timerLabel;
|
||||
private long pausedTime = 0; // Zeit, die beim Pausieren bereits abgelaufen ist
|
||||
private JPanel gamePanel; // Das Spielfeld als JPanel
|
||||
private final StateManager stateManager = new StateManager();
|
||||
|
||||
|
@ -46,20 +47,42 @@ public class GameBoard extends JPanel {
|
|||
}
|
||||
|
||||
private void startTimer() {
|
||||
startTime = System.currentTimeMillis();
|
||||
timer = new Timer(1000, e -> {
|
||||
long elapsedTime = (System.currentTimeMillis() - startTime) / 1000;
|
||||
timerLabel.setText("Zeit: " + elapsedTime + " Sekunden");
|
||||
});
|
||||
timer.start();
|
||||
if (timer == null) { // Timer nur beim ersten Start erstellen
|
||||
timer = new Timer(1000, e -> {
|
||||
long elapsedTime = (System.currentTimeMillis() - startTime + pausedTime) / 1000; // Zeit berechnen
|
||||
timerLabel.setText("Zeit: " + elapsedTime + " Sekunden");
|
||||
});
|
||||
}
|
||||
startTime = System.currentTimeMillis(); // Startzeit setzen, bevor der Timer gestartet wird
|
||||
timer.start(); // Timer starten
|
||||
System.out.println("Startzeit: " + startTime);
|
||||
System.out.println("Pausierte Zeit: " + pausedTime);
|
||||
}
|
||||
|
||||
private void stopTimer() {
|
||||
if (timer != null && timer.isRunning()) {
|
||||
timer.stop(); // Timer anhalten
|
||||
pausedTime += System.currentTimeMillis() - startTime; // Zeit während der Pause speichern
|
||||
System.out.println("Timer gestoppt. Pausierte Zeit: " + pausedTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void resumeTimer() {
|
||||
startTime = System.currentTimeMillis(); // Startzeit neu setzen
|
||||
startTimer(); // Timer erneut starten
|
||||
System.out.println("Timer fortgesetzt. Startzeit: " + startTime + ", Pausierte Zeit: " + pausedTime);
|
||||
}
|
||||
|
||||
private void resetTimer() {
|
||||
if (timer != null) {
|
||||
timer.stop();
|
||||
}
|
||||
startTime = 0;
|
||||
pausedTime = 0;
|
||||
timerLabel.setText("Zeit: 0 Sekunden");
|
||||
}
|
||||
|
||||
|
||||
private JPanel createControlPanel() {
|
||||
JPanel controlPanel = new JPanel();
|
||||
|
||||
|
@ -178,8 +201,10 @@ public class GameBoard extends JPanel {
|
|||
}
|
||||
|
||||
private void showPauseMenu() {
|
||||
stopTimer(); // Timer pausieren
|
||||
PauseMenu pauseMenu = new PauseMenu(
|
||||
(JFrame) SwingUtilities.getWindowAncestor(this),
|
||||
this, // Das aktuelle GameBoard-Objekt übergeben
|
||||
e -> startTimer(), // Spiel fortsetzen
|
||||
e -> returnToMainMenu(), // Zum Hauptmenü
|
||||
e -> System.exit(0) // Spiel beenden
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package PR2.HitoriSpiel.Fassade;
|
||||
|
||||
public class GameManager {
|
||||
private static GameBoard gameBoard;
|
||||
|
||||
public static void setGameBoard(GameBoard gb) {
|
||||
gameBoard = gb;
|
||||
}
|
||||
|
||||
public static void resumeTimer() {
|
||||
if (gameBoard != null) {
|
||||
gameBoard.resumeTimer();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,40 +25,6 @@ public class BoardLoader {
|
|||
}
|
||||
}
|
||||
|
||||
/* public static List<String> loadBoardsAsList() {
|
||||
List<String> boardFiles = new ArrayList<>();
|
||||
try {
|
||||
var resource = BoardLoader.class.getClassLoader().getResource("persistent/Hitori_Spielfelder/");
|
||||
if (resource == null) {
|
||||
throw new IOException("Das Verzeichnis 'persistent/Hitori_Spielfelder/' wurde nicht gefunden.");
|
||||
}
|
||||
|
||||
if (resource.getProtocol().equals("file")) {
|
||||
// Zugriff auf das Dateisystem (IDE-Umgebung)
|
||||
File directory = new File(resource.toURI());
|
||||
for (File file : directory.listFiles()) {
|
||||
if (file.isFile() && file.getName().endsWith(".csv")) {
|
||||
boardFiles.add(file.getName());
|
||||
}
|
||||
}
|
||||
} else if (resource.getProtocol().equals("jar")) {
|
||||
// Zugriff im JAR
|
||||
String path = resource.getPath().substring(5, resource.getPath().indexOf("!")); // JAR-Pfad extrahieren
|
||||
try (JarFile jar = new JarFile(URLDecoder.decode(path, "UTF-8"))) {
|
||||
Enumeration<JarEntry> entries = jar.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
String name = entries.nextElement().getName();
|
||||
if (name.startsWith("persistent/Hitori_Spielfelder/") && name.endsWith(".csv")) {
|
||||
boardFiles.add(name.substring(name.lastIndexOf("/") + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Fehler beim Laden der Spielfelder: " + e.getMessage());
|
||||
}
|
||||
return boardFiles;
|
||||
}*/
|
||||
public static List<String> loadBoardsAsList() {
|
||||
List<String> boardFiles = new ArrayList<>();
|
||||
try {
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
package PR2.HitoriSpiel.GUI;
|
||||
|
||||
import PR2.HitoriSpiel.Fassade.Setup;
|
||||
import PR2.HitoriSpiel.Fassade.GameBoard;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class PauseMenu extends JDialog {
|
||||
private final GameBoard gameBoard;
|
||||
|
||||
public PauseMenu(JFrame parent, ActionListener resumeAction, ActionListener mainMenuAction, ActionListener exitAction) {
|
||||
public PauseMenu(JFrame parent, GameBoard gameBoard, ActionListener resumeAction, ActionListener mainMenuAction, ActionListener exitAction) {
|
||||
super(parent, "Pause", true);
|
||||
this.gameBoard = gameBoard; // Instanz speichern
|
||||
setLayout(new GridLayout(3, 1));
|
||||
setSize(300, 200);
|
||||
setLocationRelativeTo(parent);
|
||||
|
@ -21,6 +24,8 @@ public class PauseMenu extends JDialog {
|
|||
if (resumeAction != null) {
|
||||
resumeAction.actionPerformed(e);
|
||||
}
|
||||
// Timer fortsetzen
|
||||
gameBoard.resumeTimer();
|
||||
});
|
||||
|
||||
// "Zum Hauptmenü"-Button
|
||||
|
|
Loading…
Reference in New Issue