Skip to content

Commit

Permalink
rename LocalScoreManager to LocalStorageManager
Browse files Browse the repository at this point in the history
gabrielecirulli committed Mar 22, 2014

Unverified

No user is associated with the committer email.
1 parent bd7f896 commit 08c50df
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ <h1 class="title">2048</h1>
<script src="js/html_actuator.js"></script>
<script src="js/grid.js"></script>
<script src="js/tile.js"></script>
<script src="js/local_score_manager.js"></script>
<script src="js/local_storage_manager.js"></script>
<script src="js/game_manager.js"></script>
<script src="js/application.js"></script>
</body>
2 changes: 1 addition & 1 deletion js/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Wait till the browser is ready to render the game (avoids glitches)
window.requestAnimationFrame(function () {
new GameManager(4, KeyboardInputManager, HTMLActuator, LocalScoreManager);
new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
});
22 changes: 11 additions & 11 deletions js/local_score_manager.js → js/local_storage_manager.js
Original file line number Diff line number Diff line change
@@ -18,15 +18,15 @@ window.fakeStorage = {
}
};

function LocalScoreManager() {
function LocalStorageManager() {
this.bestScoreKey = "bestScore";
this.gameStateKey = "gameState";

var supported = this.localStorageSupported();
this.storage = supported ? window.localStorage : window.fakeStorage;
}

LocalScoreManager.prototype.localStorageSupported = function () {
LocalStorageManager.prototype.localStorageSupported = function () {
var testKey = "test";
var storage = window.localStorage;

@@ -39,23 +39,23 @@ LocalScoreManager.prototype.localStorageSupported = function () {
}
};

LocalScoreManager.prototype.getBestScore = function () {
LocalStorageManager.prototype.getBestScore = function () {
return this.storage.getItem(this.bestScoreKey) || 0;
};

LocalScoreManager.prototype.setBestScore = function (score) {
LocalStorageManager.prototype.setBestScore = function (score) {
this.storage.setItem(this.bestScoreKey, score);
};

LocalScoreManager.prototype.getGameState = function () {
var stateJSON = this.storage.getItem(this.gameStateKey);
return stateJSON ? JSON.parse(stateJSON) : null;
LocalStorageManager.prototype.getGameState = function () {
var stateJSON = this.storage.getItem(this.gameStateKey);
return stateJSON ? JSON.parse(stateJSON) : null;
};

LocalScoreManager.prototype.setGameState = function (gameState) {
this.storage.setItem(this.gameStateKey, JSON.stringify(gameState));
LocalStorageManager.prototype.setGameState = function (gameState) {
this.storage.setItem(this.gameStateKey, JSON.stringify(gameState));
};

LocalScoreManager.prototype.clearGameState = function () {
this.storage.removeItem(this.gameStateKey);
LocalStorageManager.prototype.clearGameState = function () {
this.storage.removeItem(this.gameStateKey);
};

0 comments on commit 08c50df

Please sign in to comment.