Snake Game in C++
A classic Snake game implemented in C++ for the console/terminal.
Features
- 🐍 Classic snake gameplay
- 🍎 Random fruit spawning
- 📊 Score tracking
- ⌨️ WASD controls
- 🔄 Wrap-around walls (snake appears on opposite side)
- 💥 Collision detection with snake body
Files
snake_game_macos.cpp- Cross-platform version (works on macOS/Linux)snake_game.cpp- Windows version (uses Windows-specific functions)Makefile- Build configuration
How to Build and Run
On macOS/Linux:
# Build the game
make
# Or build and run in one command
make run
# Clean build files
make clean
Manual compilation:
# For macOS/Linux
g++ -std=c++11 -o snake_game_macos snake_game_macos.cpp
# Run the game
./snake_game_macos
Controls
- W - Move Up
- A - Move Left
- S - Move Down
- D - Move Right
- X - Quit Game
Game Rules
- Control the snake (O) to eat fruits (F)
- Each fruit eaten increases your score by 10 points
- The snake grows longer each time it eats a fruit
- Game ends if the snake collides with its own body
- The snake wraps around the screen edges
Game Elements
O- Snake heado- Snake bodyF- Fruit#- Walls/borders
Requirements
- C++ compiler with C++11 support (g++, clang++)
- Terminal/console environment
- macOS, Linux, or Windows
Notes
- The game uses terminal-specific functions for input and display
- On macOS/Linux, it uses POSIX terminal functions
- The Windows version uses Windows-specific console functions
- Game speed can be adjusted by modifying the sleep duration in the code
Deployment Options
🌐 Online Platforms
Replit (Recommended for Quick Demo)
- Fork this repository on GitHub
- Import to Replit from GitHub
- Run with the green "Run" button
- Share the public link
GitHub Codespaces
- Open this repository in GitHub
- Click "Code" → "Codespaces" → "Create codespace"
- Run
make runin the terminal
itch.io (Game Distribution)
- Build executable:
make - Package for distribution
- Upload to itch.io with screenshots
🐳 Docker Deployment
# Build Docker image
docker build -t snake-game .
# Run container
docker run -it snake-game
☁️ Cloud Hosting
The game can be deployed on:
- AWS EC2 - Virtual machines
- Google Cloud Run - Containerized apps
- Heroku - Easy deployment platform
- DigitalOcean - Simple cloud hosting
Enjoy the game! 🎮
Deployment Options
🌐 Online Platforms
Replit (Recommended for Quick Demo)
- Fork this repository on GitHub
- Import to Replit from GitHub
- Run with the green "Run" button
- Share the public link
GitHub Codespaces
- Open this repository in GitHub
- Click "Code" → "Codespaces" → "Create codespace"
- Run
make runin the terminal
itch.io (Game Distribution)
- Build executable:
make - Package for distribution
- Upload to itch.io with screenshots
🐳 Docker Deployment
# Build Docker image
docker build -t snake-game .
# Run container
docker run -it snake-game
☁️ Cloud Hosting
The game can be deployed on:
- AWS EC2 - Virtual machines
- Google Cloud Run - Containerized apps
- Heroku - Easy deployment platform
- DigitalOcean - Simple cloud hosting
Log in or sign up for Devpost to join the conversation.