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
+24
View File
@@ -0,0 +1,24 @@
function LocalScoreManager() {
this.key = 'bestScore';
}
LocalScoreManager.prototype.get = function () {
if (!this.isSupported()) {
return 0;
}
return localStorage.getItem(this.key);
};
LocalScoreManager.prototype.set = function (score) {
if (!this.isSupported()) {
return false;
}
localStorage.setItem(this.key, score);
};
LocalScoreManager.prototype.isSupported = function () {
return !!window.localStorage;
};