High scores

This commit is contained in:
synth-ruiner 2015-03-18 20:41:42 +00:00
parent 782172c4a7
commit 8d74d5c366
1 changed files with 15 additions and 0 deletions

View File

@ -485,8 +485,22 @@
if (isGameOver()) { if (isGameOver()) {
$('#gameOver').show(); $('#gameOver').show();
var currentHiScore = 0;
if ($.isNumeric(localStorage.getItem("hiscore"))) {
currentHiScore = parseInt(localStorage.getItem("hiscore"));
}
if (score > currentHiScore) {
currentHiScore = score;
}
$('#gameOver .score').text(score);
$('#gameOver .hiscore').text(currentHiScore);
//clear saved game //clear saved game
localStorage.clear(); localStorage.clear();
localStorage.setItem("hiscore", currentHiScore);
} }
} }
@ -832,6 +846,7 @@
<div id="game"></div> <div id="game"></div>
<div id="gameOver"> <div id="gameOver">
<h1>game over</h1> <h1>game over</h1>
<p>score: <span class="score"></span> personal best: <span class="hiscore"></span></p>
<p>a game by max bradbury</p> <p>a game by max bradbury</p>
<p>inspirations include minesweeper, tetris and 2048</p> <p>inspirations include minesweeper, tetris and 2048</p>
<p>tell your friends</p> <p>tell your friends</p>