Console Snake Game
Build the classic Snake game in C++ for the terminal with ncurses: steer the snake with the arrow keys, eat food to grow longer, and avoid hitting the walls or yourself, while the game gets faster as your score rises. The snake is stored as a std::deque of positions, which makes moving cheap (add a new head, remove the tail), food appears at random free spots, and the best score is saved to a file. It's a fun first C++ project: you'll learn ncurses for drawing and keyboard input without waiting, a game loop with timing, std::deque, random numbers, collision detection, and organizing a program into small classes.
- Estimate
- ~7.5h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
ncurses
Project roadmap
- 01
Set up ncurses and the game loop
~1.5hInstall the ncurses development package and set up a CMake project linking it. Initialize ncurses (initscr, cbreak, noecho, keypad, curs_set(0) and nodelay so getch doesn't wait), draw a border for the play area, and write a loop that runs a fixed number of times per second using std::this_thread::sleep_for, always calling endwin on exit. Done when: the program shows a bordered area and exits cleanly with q.
- 02
Move the snake
~1.5hStore the snake as a std::deque of (row, column) positions, starting with 3 segments. Each tick, add a new head in the current direction and remove the tail. Change direction with the arrow keys, ignoring a reverse turn (going left while moving right). Draw the head and body with different characters. Done when: the snake moves smoothly and turns with the arrow keys.
- 03
Add food and growth
~1hPlace food at a random empty position (never on the snake), using std::mt19937 seeded from the clock. When the head reaches the food, increase the score and skip removing the tail for that tick, so the snake grows, then place new food. Show the score above the play area. Done when: eating food grows the snake and increases the score.
- 04
Detect collisions
~1hEnd the game when the head hits the border or any part of the body. Show a game over message with the score, and offer to play again or quit. Handle the case where the snake fills the whole area (a win). Done when: hitting a wall or yourself ends the game, and restarting works.
- 05
Increase the difficulty
~1hMake the game speed up as the score grows (shortening the delay between ticks, down to a minimum), and save the best score to a file in the user's home folder, loading it at start and showing it on screen. Add p to pause. Done when: the game gets faster as you score, and the best score is kept between runs.
- 06
Test the game logic
~1.5hSeparate the game rules (moving, growing, collisions and food placement) from the ncurses drawing into a class that doesn't use ncurses, and write tests for it (with doctest or Catch2): moving, not reversing direction, growing, wall and self collisions, and food never placed on the snake. Done when: the tests pass.
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack