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 – building the draw-and-guess game

We will implement the game flow of the draw-and-guess game as follows:

  1. First, we will add the game logic on the client side.
  2. Open the index.html file in the client directory. Add the following restart button right after the send button:
    <input type="button" value="Restart" id="restart">
  3. Open the html5games.websocket.js JavaScript.
  4. We need a few more constants to determine different states during the game play. Add the following highlighted code to the top of the file:
    // Constants
    LINE_SEGMENT : 0,
    CHAT_MESSAGE : 1,
    GAME_LOGIC : 2,
    
    // Constant for game logic state
    WAITING_TO_START : 0,
    GAME_START : 1,
    GAME_OVER : 2,
    GAME_RESTART : 3,
    
  5. In addition, we want a flag to indicate this player is in charge of ...

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