Snake

Back to projects list

AnimationCanvas

Snake is a classic video game that's so old that I can remember typing in code from a computer magazine to make a Snake game on an original IBM PC in the early 80s.

The player controls an always-moving snake that wanders around a square playing area. It starts out one segment long but each time the snake eats one of the apples that appear at random on the board (by hitting the apple with it's head segment) the snake grows by one segment. The game ends when the snake crashes into a wall or its own body.

It is not too hard to make a simple version of snake but there are some subtleties and also plenty of enhancements you can make if you want. For instance, to start with it's reasonable to make it so the snake moves one square at a time but that can lead to somewhat jerky motion. If you want a challenge, figure out how to animate the snake more smoothly.

If you really need a challenge, write an autoplay mode. The "Snake with autoplay" listed in the references below uses a fairly simple algorithm to get pretty good results but it is far from perfect. There are presumably other ways to do it.

References