Classic Python Snake Game Using pygame [pip install pygame]
The snake starts at the center of the board, moving north (upward). The snake moves at a constant speed. The snake moves only north, south, east, or west (ignore the versions of the game where the snake can move in curves). The snake "moves" by adding a square to its head and simultaneously deleting a square from the tip of its tail. "Apples" appear at random locations, and persist for a random amount of time (but usually long enough for it to be possible for the snake to get to the apple). There is always exactly one apple visible at any given time. When the snake "eats" (runs into) an apple, it gets longer. (This is hard to describe, so play a couple of games to see what I mean.) When the snake gets longer, say by n squares, it does so by not deleting squares from its tail for the next n moves. The game continues until the snake "dies". A snake dies by either (1) running into the edge of the board, or (2) by running into its own tail. The final score is based on the number of apples eaten by the snake. The snake can be controlled by the arrow keys. (You can use additional keysets if you like, but use at least these.) There should also be a way to pause/resume the game (usually the "P" key).
- MIT