- 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:
Marshall
2012-04-28 23:01:36 -04:00
parent a6af6df132
commit dc11e2c48b
8 changed files with 180 additions and 8 deletions

View File

@@ -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);
}
}