Book Image

HTML5 Game Development by Example: Beginner's Guide

By : Seng Hin Mak
Book Image

HTML5 Game Development by Example: Beginner's Guide

By: Seng Hin Mak

Overview of this book

Table of Contents (18 chapters)
HTML5 Game Development by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
9
Building a Physics Car Game with Box2D and Canvas
Index

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 = matchingGame.deck.slice();
    });
  3. Still in the jQuery document ready function, we append the following highlighted code to the end of the function. It removes any card that was marked as removed in the saved data. We also restore...