85 lines
2.1 KiB
Java
85 lines
2.1 KiB
Java
package domain;
|
|
|
|
import domain.GameSolver;
|
|
|
|
import java.io.*;
|
|
|
|
public class HitoriGameMain extends GameSolver {
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private final domain.HitoriGameTimer timer;
|
|
private final domain.HitoriGameScores scores;
|
|
|
|
public HitoriGameMain(int[][] initialBoard) {
|
|
super(initialBoard);
|
|
this.timer = new domain.HitoriGameTimer();
|
|
this.scores = new HitoriGameScores();
|
|
}
|
|
|
|
// Timer delegation methods
|
|
public void startTimer() {
|
|
timer.startTimer();
|
|
}
|
|
|
|
public void pauseTimer() {
|
|
timer.pauseTimer();
|
|
}
|
|
|
|
public void stopTimer() {
|
|
timer.stopTimer();
|
|
}
|
|
|
|
public void resetTimer() {
|
|
timer.resetTimer();
|
|
}
|
|
|
|
public long getElapsedTimeInSeconds() {
|
|
return timer.getElapsedTimeInSeconds();
|
|
}
|
|
|
|
// High score delegation methods
|
|
public void addHighScore(String playerName, long timeInSeconds) {
|
|
scores.addHighScore(playerName, timeInSeconds, getMistakeCount());
|
|
}
|
|
|
|
public void deleteHighScores() {
|
|
scores.deleteHighScores();
|
|
}
|
|
|
|
public java.util.List<String> getHighScoresWithAverage() {
|
|
return scores.getHighScoresWithAverage();
|
|
}
|
|
|
|
public void loadHighScoresFromFile() {
|
|
scores.loadHighScoresFromFile();
|
|
}
|
|
|
|
public void saveHighScoresToFile() {
|
|
scores.saveHighScoresToFile();
|
|
}
|
|
|
|
// Game state persistence
|
|
public void saveGameState() {
|
|
try (ObjectOutputStream oos = new ObjectOutputStream(
|
|
new FileOutputStream("gamestate.dat"))) {
|
|
oos.writeObject(this);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static HitoriGameMain loadGameState() {
|
|
try (ObjectInputStream ois = new ObjectInputStream(
|
|
new FileInputStream("gamestate.dat"))) {
|
|
return (HitoriGameMain) ois.readObject();
|
|
} catch (IOException | ClassNotFoundException e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void reset() {
|
|
super.reset();
|
|
resetTimer();
|
|
}
|
|
} |