- Implemented saving and loading of a player model. High scores are now persistent, though only for one user.
- Created a JUnit test class to test the serialization. Should be useful for later tests.
This commit is contained in:
@@ -28,14 +28,14 @@ public class Referee implements Runnable {
|
||||
|
||||
private final HumanPlayer humanPlayer = new HumanPlayer();
|
||||
private final MainFrame mf;
|
||||
private final PlayerModel playerModel;
|
||||
private PlayerModel playerModel = null;
|
||||
|
||||
public Referee(MainFrame mnFrm) {
|
||||
if (PlayerModel.TRY_LOAD && PlayerModel.exists()) {
|
||||
playerModel = PlayerModel.load();
|
||||
}
|
||||
|
||||
else {
|
||||
if (playerModel == null) {
|
||||
playerModel = new PlayerModel();
|
||||
}
|
||||
|
||||
@@ -84,6 +84,11 @@ public class Referee implements Runnable {
|
||||
mf.updateBoard();
|
||||
play();
|
||||
playerModel.logGame(getPlayerScore());
|
||||
|
||||
if (!playerModel.save()) {
|
||||
System.err.println("Saving PlayerModel failed.");
|
||||
}
|
||||
|
||||
new HighScoreDialog(mf, playerModel);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user