O'Reilly logo

HTML5 Game Development by Example : Beginner's Guide - Second Edition by Makzan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required