Store best score in localStorage

Dependency injection and hide best score for incompatible browsers
This commit is contained in:
Tim Petricola
2014-03-10 16:02:16 -04:00
parent 57deb5d998
commit 664546ef9a
7 changed files with 86 additions and 17 deletions
+12 -5
View File
@@ -1,7 +1,8 @@
function GameManager(size, InputManager, Actuator) {
function GameManager(size, InputManager, Actuator, ScoreManager) {
this.size = size; // Size of the grid
this.inputManager = new InputManager;
this.actuator = new Actuator;
this.scoreManager = new ScoreManager;
this.actuator = new Actuator(this.scoreManager.isSupported());
this.startTiles = 2;
@@ -51,11 +52,17 @@ GameManager.prototype.addRandomTile = function () {
// Sends the updated grid to the actuator
GameManager.prototype.actuate = function () {
if (this.scoreManager.get() < this.score) {
this.scoreManager.set(this.score);
}
this.actuator.actuate(this.grid, {
score: this.score,
over: this.over,
won: this.won
score: this.score,
over: this.over,
won: this.won,
bestScore: this.scoreManager.get()
});
};
// Save all tile positions and remove merger info