Skip to content

arya-dev2005/Snake-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

███████╗███╗   ██╗ █████╗ ██╗  ██╗███████╗
██╔════╝████╗  ██║██╔══██╗██║ ██╔╝██╔════╝
███████╗██╔██╗ ██║███████║█████╔╝ █████╗  
╚════██║██║╚██╗██║██╔══██║██╔═██╗ ██╔══╝  
███████║██║ ╚████║██║  ██║██║  ██╗███████╗
╚══════╝╚═╝  ╚═══╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝

 ██████╗  █████╗ ███╗   ███╗███████╗
██╔════╝ ██╔══██╗████╗ ████║██╔════╝
██║  ███╗███████║██╔████╔██║█████╗  
██║   ██║██╔══██║██║╚██╔╝██║██╔══╝  
╚██████╔╝██║  ██║██║ ╚═╝ ██║███████╗
 ╚═════╝ ╚═╝  ╚═╝╚═╝     ╚═╝╚══════╝

🐍 Console Based Snake Game in C++

⚡ A classic arcade Snake Game built in terminal using arrays, loops, collision detection, and real-time keyboard controls.


📖 About The Project

This project is a console-based implementation of the classic Snake Arcade Game developed in C++ using procedural programming fundamentals.

The game executes entirely inside the terminal and demonstrates:

  • ⚡ Real-time keyboard event handling
  • 🎮 Frame-based rendering loop
  • 🐍 Snake body movement using arrays
  • 🍎 Random food generation
  • 💥 Collision detection (wall + self)
  • 📊 Score tracking and HUD display
  • 🔁 Restart and exit controls

No external libraries — pure system-level programming.


🎮 Live Gameplay Preview

github-snake


✨ Key Features

Feature Description
🎯 Real-Time Input Uses _kbhit() and _getch() for non-blocking keyboard capture
🐍 Dynamic Snake Growth Snake length increases after consuming food
🍎 Random Food Logic Food spawns randomly within board boundaries
💥 Collision Engine Detects self-hit and wall-hit conditions
📊 HUD Display Live score, length, controls, objective shown on top
🔁 Restart Option Allows replay after Game Over
🎨 Console Styling Colored borders and terminal UI enhancement

🧠 Core Concepts

Snake Representation

int snakeX[MAX_LENGTH], snakeY[MAX_LENGTH];

Game Loop

while (!gameOver)
{
    handleInput();
    update();
    draw();
    Sleep(SPEED_MS);
}

Collision Detection

  • Boundary checks
  • Self overlap detection
  • Food consumption → growth

⚙️ Installation & Execution

Clone Repository

git clone https://github.com/arya-dev2005/Snake-Game.git

Enter Folder

cd Snake-Game

Compile

g++ snake_game.cpp -o snake_game

Run

snake_game.exe

🎮 Controls

Key Action
W / ↑ Move Up
S / ↓ Move Down
A / ← Move Left
D / → Move Right
Q Quit
R Restart

🧱 Project Structure

Snake-Game/
│── snake_game.cpp
│── README.md
│── snake_preview.png
│── .github/
│   └── workflows/
│       └── snake.yml

⚡ Technical Highlights

  • Efficient array-based snake movement
  • Non-blocking input handling
  • Flicker-free rendering using cursor control
  • Clean procedural design architecture

🚀 Future Improvements

  • 🎨 Themes / color modes
  • 🔊 Sound effects
  • 🧠 AI Snake mode
  • 🌐 Cross-platform support
  • 🧩 OOP-based refactor

🤝 Contributing

Pull requests are welcome. For major changes, please open an issue first.


📜 License

This project is open-source under the MIT License.


⭐ If you like this project, give it a star!

About

Console based snake game

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages