This chapter will take on the often copied game that has graced pretty much every possible computing platform, from early cell phones to current consoles: the snake game. There are many variations under a variety of names, but the mechanics are generally the same. You control a snake that is always moving forward. You can turn the snake right or left (at right angles only), avoiding walls and eating mice (or other food). Each time you eat something, your snake gets longer. You can go on eating (and growing) until you run into a wall or your own tail.
The "classic" way to handle the snake's movement in a snake game is to draw a new body segment in the direction the snake is moving, and erase the one at the end. While this approach works, we want to use a more object-oriented approach in our design.
We will focus on letting the snake be as autonomous as possible. We want a snake
class that we can simply instruct to move, and the
snake
object will handle the movement...