O'Reilly logo

JavaScript for Kids by Nick Morgan

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

Chapter 17. Making a Snake Game: Part 2

In this chapter, we’ll finish building our Snake game. In Chapter 16, we set up the playing area and covered how the game would work in general. Now we’ll create the objects that represent the snake and apple in the game, and we’ll program a keyboard event handler so that the player can control the snake with the arrow keys. Finally, we’ll look at the complete code listing for the program.

As we create the snake and apple objects for this game, we’ll use the object-oriented programming techniques we learned in Chapter 12 to create constructors and methods for each object. Both our snake and apple objects will rely on a more basic block object, which we’ll use to represent one block on the game board grid. ...

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