Time for action – resuming a game from the local storage

Carry out the following steps:

  1. Open the matchgame.js JavaScript file.
  2. In the jQuery document ready function, we used the saved order of the deck in the previous game instead of shuffling a new deck. Add the following highlighted code in the jQuery ready function:
    $(document).ready(function(){
      // reset the elapsed time to 0.
      matchingGame.elapsedTime = 0;
    
      // start the timer
      matchingGame.timer = setInterval(countTimer, 1000);
    
    // shuffling the deck
      matchingGame.deck.sort(shuffle);
    
      // re-create the saved deck
      var savedObject = savedSavingObject();
      if (savedObject !== undefined) {
        matchingGame.deck = savedObject.deck;
      }
    
      // copying the deck into saving object. matchingGame.savingObject.deck = ...

Get HTML5 Game Development by Example : Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.