A classic console-based Snake Game written in C++, designed for beginners to learn:
- Game loops
- Real-time input handling
- Tail-follow mechanics
- Collision detection
- Rendering tricks
- Practical use of arrays
- Smooth screen updates
This version includes:
✔ Smooth screen rendering (no flicker)
✔ Wall Mode & No-Wall (Wrap-Around) Mode
✔ Snake tail that grows properly
✔ Speed boost
✔ Score system
✔ Collision detection
✔ Cursor hiding for clean visuals
✔ Beginner-friendly structure
- Move using W / A / S / D
- Eat fruit (F) to grow
- Gain +1 score per fruit
- Press Spacebar for temporary speed boost
- Press X to exit instantly
- Wall Mode → hitting the wall ends the game
- No-Wall Mode (Wrap-Around) → snake appears from the opposite side
Each frame runs the loop:
input() → logic() → gameOverFunc() → draw()
- The snake head moves first
- Each tail segment copies the position of the segment in front of it
- The first tail segment follows the old head position
Arrays used:
int tailX[100], tailY[100];
int nTail;Instead of clearing the screen, we reposition the cursor:
SetConsoleCursorPosition()This removes flicker completely.
##############################
# #
# #
# #
# #
# oooO #
# #
# F #
# #
##############################
Score = 3.
├── SnakeGame.cpp
├── README.md
├── LICENSE
└── .gitignore| Key | Action |
|---|---|
| W | Move Up |
| A | Move Left |
| S | Move Down |
| D | Move Right |
| Spacebar | Speed Boost |
| X | Quit Game |
Compile:
g++ SnakeGame.cpp -o snakeRun:
./snake- Full game loop implementation
- Real-time keyboard input
- Tail movement logic
- Collision detection
- Console-based rendering
- Multiple game modes
- Speed manipulation
- Basic game physics
🤝 Contributing
Pull requests are welcome! Feel free to improve logic, visuals, or add new mechanics.
This project is open-source and licensed under the MIT License. See the separate LICENSE file for details.