3.5 ZZZZZnake
A classic computer game is Snake . On the screen is a player, a snake, some gold, and a door. The door and the gold are fixed, the player can be moved, and the snake moves independently towards the player. You must try to move the player to the gold and then to the door. If the snake catches you before you achieve these goals, you’re unlucky, and it’s game over.
This game may sound complex at first glance, but you already have all the building blocks to program this game:
-
Player, Snake, Gold, and Door are Point objects preconfigured with coordinates.
-
A loop runs through all coordinates. If a player, the door, the snake, or gold has been “hit,” a symbolic representation of the figure is displayed.
-
You’ll test three conditions ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access