A CLI-based Snake game implementation in C++20.
Classic Snake game where the player controls a snake that grows by eating fruits. The game ends when the snake hits a wall or bites its own tail.
- Navigate the snake using ZQSD keys
- Eat fruits (@) to grow and earn points
- Each fruit gives 10 points
- Avoid walls and your own tail
- The snake moves continuously in the current direction
# Clone the repository
git clone https://github.com/yourusername/snake_game.git
cd snake_game
# Create build directory
mkdir build
cd build
# Configure and compile
cmake ..
cmake --build .# From the build directory
./snakeZ- Move upS- Move downQ- Move leftD- Move rightCtrl+C- Quit game
snake_game/
├── include/ # Header files
│ ├── Board.hpp
│ ├── Constants.hpp
│ ├── Direction.hpp
│ ├── Fruit.hpp
│ ├── Input.hpp
│ ├── Position.hpp
│ └── Snake.hpp
├── src/ # Source files
│ ├── Board.cpp
│ ├── Direction.cpp
│ ├── Fruit.cpp
│ ├── Input.cpp
│ ├── main.cpp
│ ├── position.cpp
│ └── Snake.cpp
├── CMakeLists.txt
└── README.md
The game is built around several key components:
- Position: Represents coordinates on the board
- Direction: Manages movement directions
- Snake: Handles snake logic, movement, and collision detection
- Fruit: Manages fruit spawning and point values
- Board: Manages game boundaries and fruit placement
- Input: Handles keyboard input in non-blocking mode
Game parameters can be modified in include/Constants.hpp:
constexpr int BOARD_WIDTH = 30;
constexpr int BOARD_HEIGHT = 20;
constexpr int FRUIT_POINTS = 10;