How kelwynoliveira/pysnake works
PySnake is a single-file terminal Snake game. The user selects a speed, then steers the snake while the game loop updates its position, checks fruit and collisions, tracks score, and displays the result. The diagram separates control, game rules, and terminal presentation while keeping the actual function-call ownership visible. All runtime code is in pysnake.py; the README documents the gameplay and difficulty levels, and the supplied source shows their implementation.
Main entry points: pysnake.py Game loop
Components 19
Game control
- Program entry
pysnake.py - Difficulty selection
pysnake.py - Game loop
pysnake.py - End-game screen
pysnake.py
Game rules
- Move snake
pysnake.py - Move actor
pysnake.py - Reject reversal
pysnake.py - Check fruit
pysnake.py - Spawn fruit
pysnake.py - Self collision
pysnake.py - Border collision
pysnake.py - Check border
pysnake.py
Terminal interface
- Read direction
pysnake.py - Draw screen
pysnake.py - Draw snake
pysnake.py - Draw actor
pysnake.py
Other components
- Player
- Python random
- Terminal
Connections 23
- Player → Difficulty selection: chooses speed
- Program entry → Difficulty selection: selects speed
- Program entry → Game loop: launches game
- Player → Read direction: presses keys
- Game loop → Read direction: reads input
- Game loop → Draw screen: draws frame
- Game loop → Draw snake: draws snake
- Game loop → Draw actor: draws fruit
- Game loop → Reject reversal: checks reversal
- Game loop → Move snake: moves snake
- Move snake → Move actor: moves head
- Game loop → Border collision: checks border
- Border collision → Check border: checks head
- Game loop → Self collision: checks self-hit
- Game loop → Check fruit: checks fruit
- Game loop → Spawn fruit: spawns fruit
- Spawn fruit → Python random: chooses position
- Game loop → End-game screen: shows score
- Draw screen → Terminal: draws frame
- Draw snake → Draw actor: draws segments
- Draw actor → Terminal: writes characters
- Read direction → Terminal: reads keys
- End-game screen → Terminal: shows result