Saving/loading functionality
Also removed an unused variable
This commit is contained in:
parent
546a30a96a
commit
54b38fbb04
35
index.html
35
index.html
|
@ -285,7 +285,6 @@
|
|||
var gameBoardHeight = 9;
|
||||
var score = 0;
|
||||
var firstClick = true;
|
||||
var currentlyIterating = false;
|
||||
var mineChance = 0.2;
|
||||
var clickholdMs = 200;
|
||||
var timeout; //hold timer
|
||||
|
@ -328,6 +327,37 @@
|
|||
return row;
|
||||
}
|
||||
|
||||
function saveGame() {
|
||||
if (typeof(Storage) == "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
//variables
|
||||
localStorage.setItem("score", score);
|
||||
localStorage.setItem("mineChance", mineChance);
|
||||
localStorage.setItem("firstClick", firstClick);
|
||||
|
||||
//game board
|
||||
localStorage.setItem("gameBoard", $('#game').html());
|
||||
}
|
||||
|
||||
function loadGame() {
|
||||
//check if storage available and if saved game exists
|
||||
if (typeof(Storage) == "undefined" || localStorage.getItem("gameBoard") == null) {
|
||||
drawGameBoard();
|
||||
return;
|
||||
}
|
||||
|
||||
//variables
|
||||
score = parseInt(localStorage.getItem("score"));
|
||||
mineChance = parseFloat(localStorage.getItem("mineChance"));
|
||||
firstClick = (localStorage.getItem("firstClick") == "true");
|
||||
|
||||
//game board
|
||||
$('#game').html(localStorage.getItem("gameBoard"));
|
||||
$('#setup').hide();
|
||||
}
|
||||
|
||||
$.fn.check = function() {
|
||||
//unclicked tiles
|
||||
if ($(this).filter('li:not(.revealed):not(.flagged)').length > 0) {
|
||||
|
@ -748,6 +778,7 @@
|
|||
|
||||
updateScore();
|
||||
updateMinesLeft();
|
||||
saveGame();
|
||||
});
|
||||
|
||||
$(window).resize(function() {
|
||||
|
@ -757,7 +788,7 @@
|
|||
resizeToWindow();
|
||||
|
||||
//instantiate the game
|
||||
drawGameBoard();
|
||||
loadGame(); //loadGame will draw the game board if no saved game is found
|
||||
|
||||
$('#gameOver').hide();
|
||||
$('button.cancel').hide();
|
||||
|
|
Loading…
Reference in New Issue