Time for action – saving all essential game data in the local storage
We will continue work with our CSS3 card matching game:
- Open the
matchgame.js
JavaScript file. - Add the following code at the top of the JavaScript file after declaring the
matchingGame
variable. This code creates an object namedsavingObject
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;
- In the jQuery
ready
function, add the following highlighted code. It clones the order of the deck to thesavingObject ...
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.