First, we need to add a few markups in the
popup
section to display the last score. Add the following HTML inpopup-box
inindex.html
. The changed code is highlighted:<section id="popup" class="hide"> <div id="popup-bg"> </div> <div id="popup-box"> <div id="popup-box-content"> <h1>You Won!</h1> <p>Your Score:</p> <p><span class='score'>13</span></p> <p> <small>Last Score: <span class='last-score'>20</span> </small> </p> </div> </div> </section>
Then, we open the
matchgame.js
to modify some game logic in thegameover
function.Add the following highlighted code in the
gameover
function. It loads the saved score from the local storage and displays it as the score last time. Then, we save the current score in the local storage:function gameover() { // stop the...
HTML5 Game Development by Example: Beginner's Guide
By :
HTML5 Game Development by Example: Beginner's Guide
By:
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
Free Chapter
Introducing HTML5 Games
Getting Started with DOM-based Game Development
Building a Card-matching Game in CSS3
Building the Untangle Game with Canvas and the Drawing API
Building a Canvas Game's Masterclass
Adding Sound Effects to Your Games
Saving the Game's Progress
Building a Multiplayer Draw-and-Guess Game with WebSockets
Building a Physics Car Game with Box2D and Canvas
Deploying HTML5 Games
Pop Quiz Answers
Index
Customer Reviews