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

  1. Control the snake (O) to eat fruits (F)
  2. Each fruit eaten increases your score by 10 points
  3. The snake grows longer each time it eats a fruit
  4. Game ends if the snake collides with its own body
  5. The snake wraps around the screen edges

Game Elements

  • O - Snake head
  • o - Snake body
  • F - 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)

  1. Fork this repository on GitHub
  2. Import to Replit from GitHub
  3. Run with the green "Run" button
  4. Share the public link

GitHub Codespaces

  1. Open this repository in GitHub
  2. Click "Code" → "Codespaces" → "Create codespace"
  3. Run make run in the terminal

itch.io (Game Distribution)

  1. Build executable: make
  2. Package for distribution
  3. 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)

  1. Fork this repository on GitHub
  2. Import to Replit from GitHub
  3. Run with the green "Run" button
  4. Share the public link

GitHub Codespaces

  1. Open this repository in GitHub
  2. Click "Code" → "Codespaces" → "Create codespace"
  3. Run make run in the terminal

itch.io (Game Distribution)

  1. Build executable: make
  2. Package for distribution
  3. 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

Built With

Share this project:

Updates