diff --git a/js/Block.js b/js/Block.js index e4ae89c..256417b 100644 --- a/js/Block.js +++ b/js/Block.js @@ -51,7 +51,7 @@ function Block(fallingLane, color, iter, distFromHex, settled) { //slate for final deletion this.opacity = 0; this.deleted = 2; - if (gameState == 1) { + if (gameState == 1 || gameState==0) { localStorage.setItem("saveState", exportSaveState()); } } @@ -143,7 +143,7 @@ function Block(fallingLane, color, iter, distFromHex, settled) { if (this.tint) { if (this.opacity < 1) { - if (gameState == 1) { + if (gameState == 1 || gameState==0) { localStorage.setItem("saveState", exportSaveState()); } diff --git a/js/initialization.js b/js/initialization.js index ed2960c..34adc2d 100644 --- a/js/initialization.js +++ b/js/initialization.js @@ -176,13 +176,12 @@ function initialize(a) { document.addEventListener('touchmove', function(e) { e.preventDefault(); }, false); $(window).resize(scaleCanvas); $(window).unload(function(){ - - if(gameState ==1 || gameState ==-1) localStorage.setItem("saveState", exportSaveState()); + + if (gameState == 1 || gameState == -1 || gameState === 0) localStorage.setItem("saveState", exportSaveState()); else localStorage.clear(); }); addKeyListeners(); - (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-51272720-1', 'teamsnowman.github.io'); ga('send', 'pageview'); @@ -205,4 +204,4 @@ function handleTap(e) { function handleClick(e) { handleClickTap(e.clientX); -} \ No newline at end of file +} diff --git a/js/main.js b/js/main.js index 31e11ac..abeeb32 100644 --- a/js/main.js +++ b/js/main.js @@ -274,14 +274,11 @@ function enableRestart() { } function updateHighScore(){ - if(localStorage.getItem('highscores')){ - highscores = localStorage.getItem('highscores').split(',').map(Number); - } - - for (var i = 0; i < numHighScores; i++) { - if (highscores[i] <= score) { - highscores.splice(i, 0, score); - highscores = highscores.slice(0,-1); + //debugger; + for(var i = 0; i0){ @@ -103,9 +105,10 @@ function showText(text){ if (text == 'gameover') { var allZ = 1; var i; + console.log(highscores); for (i = 0; i < 3; i++) { if (highscores[i] !== undefined && highscores[i] != 0) { - messages['gameover'] += " 1. "+highscores[i] + " pts "; + messages['gameover'] += " "+(i+1)+". "+highscores[i] + " pts "; } } @@ -201,6 +204,7 @@ function hideText(text){ pt.innerHTML = ''; } function gameOverDisplay(){ + updateHighScore(); var c = document.getElementById("canvas"); c.className = "blur"; showText('gameover'); @@ -234,4 +238,4 @@ function pause(o) { prevGameState = gameState; gameState = -1; } -} \ No newline at end of file +}