fixed highscores not being saved
This commit is contained in:
parent
85b4c336fa
commit
46991a4a16
4 changed files with 20 additions and 22 deletions
|
@ -127,7 +127,7 @@ function initialize(a) {
|
|||
window.prevScore = 0;
|
||||
window.numHighScores = 3;
|
||||
|
||||
window.highscores = [];
|
||||
highscores = [];
|
||||
if (localStorage.getItem('highscores')) {
|
||||
try {
|
||||
highscores = JSON.parse(localStorage.getItem('highscores'));
|
||||
|
@ -136,7 +136,6 @@ function initialize(a) {
|
|||
}
|
||||
}
|
||||
|
||||
writeHighScores();
|
||||
|
||||
window.blocks = [];
|
||||
window.MainHex;
|
||||
|
@ -312,4 +311,4 @@ function handleClickBefore(e) {
|
|||
showHelp();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -311,4 +311,4 @@ function showHelp() {
|
|||
}
|
||||
|
||||
$('#helpScreen').fadeToggle(150, "linear");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,9 +37,22 @@ function descaleBlock(b) {
|
|||
}
|
||||
|
||||
function writeHighScores() {
|
||||
if (Object.prototype.toString.call(highscores) === '[object Array]') {
|
||||
localStorage.setItem("highscores", JSON.stringify(highscores));
|
||||
}
|
||||
debugger;
|
||||
highscores.sort(
|
||||
function(a,b){
|
||||
a = parseInt(a, 10);
|
||||
b = parseInt(b, 10);
|
||||
if (a < b) {
|
||||
return 1;
|
||||
} else if (a > b) {
|
||||
return -1;
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
);
|
||||
highscores = highscores.slice(0,3);
|
||||
localStorage.setItem("highscores", JSON.stringify(highscores));
|
||||
}
|
||||
|
||||
function clearSaveState() {
|
||||
|
|
16
js/view.js
16
js/view.js
|
@ -98,21 +98,7 @@ function showText(text){
|
|||
if (text == 'gameover') {
|
||||
var allZ = 1;
|
||||
var i;
|
||||
highscores.sort(
|
||||
function(a,b){
|
||||
a = parseInt(a, 10);
|
||||
b = parseInt(b, 10);
|
||||
if (a < b) {
|
||||
return 1;
|
||||
} else if (a > b) {
|
||||
return -1;
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
);
|
||||
highscores = highscores.slice(0,3);
|
||||
writeHighScores();
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (highscores.length > i) {
|
||||
messages['gameover'] += "<tr> <th class='tg-031e'>"+(i+1)+".</th> <th class='tg-031e'>"+highscores[i] + " pts</th> </tr>";
|
||||
|
|
Loading…
Reference in a new issue