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 the game score

  1. First, we need to add a few markups in the popup section to display the last score. Add the following HTML in popup-box in index.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>
  2. Then, we open the matchgame.js to modify some game logic in the gameover function.
  3. 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 ...

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