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 – saving all essential game data in the local storage

We will continue work with our CSS3 card matching game:

  1. Open the matchgame.js JavaScript file.
  2. Add the following code at the top of the JavaScript file after declaring the matchingGame variable. This code creates an object named savingObject to save the array of the deck, the removed cards and the current elapsed time:
    matchingGame.savingObject = {};
    
    matchingGame.savingObject.deck = [];
    
    // array to store which card is removed by their index.
    matchingGame.savingObject.removedCards = [];
    
    // store the counting elapsed time.
    matchingGame.savingObject.currentElapsedTime = 0;
  3. In the jQuery ready function, add the following highlighted code. It clones the order of the deck to the savingObject ...

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