The code
The way this game was laid out is actually quite simple. The HTML has only three widgets: the title of the game, a score board for the player's current score, and a score board for the overall high score across multiple games. This last score board is not used in this version of the game, and we'll get more into it in the next game (see Chapter 5, Improving the Snake Game).
<h1>HTML5 Snake</h1> <section id="scores"> <h3>Score: <span>0</span></h3> <h3>High Score: <span>0</span></h3> </section> <section id="gameMenu" class="hide"> <h3>Ready!</h3> <button>Play</button> </section>
In order to separate the various responsibilities from all the different components in the game, we abstracted out all the rendering for the entire game into a single Renderer
class. This class is in charge of drawing data to a canvas
reference that is given to it. The data that it draws...