A classic Snake game with two implementations: a modern web version and a terminal-based C++ version.
- Open
index.htmlin your web browser - Select difficulty: Easy 🐢, Medium 🐇, or Hard 🚀
- Use Arrow keys or WASD to control the snake
- Press P to pause
- Eat food to grow and increase your score
- Avoid hitting the walls or yourself!
- Three difficulty levels with increasing speed
- High score tracking (saved in browser)
- Mobile touch/swipe controls
- Beautiful neon-themed graphics
- Pause functionality
g++ snake.cpp -o snake
./snake- WASD or Arrow keys to move
- Q or ESC to quit
| File | Description |
|---|---|
index.html |
Web game structure - canvas, overlays, UI elements |
styles.css |
Web game styling - dark theme, neon colors, animations |
game.js |
Web game logic - snake movement, collisions, rendering |
snake.cpp |
Standalone terminal game in C++ |
index.html ──loads──► styles.css (styling)
│
└──────loads──► game.js (game logic)
Note: The web version runs entirely in the browser with no backend. High scores are stored in
localStorage.
- Snake is stored as an array of
{x, y}positions - Movement adds a new head position and removes the tail
- Eating food skips removing the tail (snake grows)
- Collision detection checks if head hits walls or body
- Speed increases as you eat more food