Skip to content

A simple game written using C++ programming language and using the following libraries: windows.h time.h

License

Notifications You must be signed in to change notification settings

MrR4di0k4l/snake-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐍 Classic Snake Adventures 🕹️

Dive into a nostalgic gaming experience with this terminal-based rendition of the timeless Snake game! Crafted with C++ and the ncurses library, this project brings the simple yet addictive fun of Snake right to your command line.


✨ Features

  • Classic Gameplay: Relive the original thrill of guiding your ever-growing snake.
  • Smooth Controls: Intuitive arrow key navigation for precise movements.
  • Dynamic Growth: Watch your snake get longer with every tasty morsel consumed.
  • Collision Detection: Beware of the walls and your own tail – a true test of skill!
  • Terminal-Powered Graphics: Retro-style visuals brought to life with the ncurses library.
  • Lightweight & Fast: Runs smoothly in most terminal environments.

🛠️ Tech Stack

  • Language: C++
  • UI/Graphics: ncurses library (for terminal-based interface)
  • Compiler: GCC / Clang (or any standard C++ compiler)

🚀 Getting Started

Ready to chase some food? Here's how to get the game up and running on your system.

📋 Prerequisites

Before you begin, ensure you have the following installed:

  1. A C++ Compiler:
    • Most Linux distributions and macOS come with g++ or clang.
  2. ncurses Library: This library is essential for the terminal graphics.
    • On Debian/Ubuntu-based systems:
      sudo apt-get update
      sudo apt-get install libncurses5-dev libncursesw5-dev
    • On Fedora/RHEL/CentOS-based systems:
      sudo dnf install ncurses-devel
    • On macOS (using Homebrew):
      brew install ncurses

⚙️ Compilation & Execution

  1. Clone the Repository (if applicable):

    # git clone <your-repository-url>
    # cd snake-game

    (If you just have the main.cpp file, skip this step and ensure main.cpp is in your current directory.)

  2. Compile the Code: Open your terminal and use the C++ compiler to build the executable. Link against the ncurses library.

    g++ main.cpp -o snake_game -lncurses
  3. Run the Game: Execute the compiled program to start playing!

    ./snake_game

🎮 How to Play

The rules are simple, but mastery is a challenge!

  • Objective: Grow your snake as long as possible by eating food.
  • Controls:
    • Arrow Up: Move Up
    • Arrow Down: Move Down
    • Arrow Left: Move Left
    • Arrow Right: Move Right
  • Game Over: The game ends if the snake collides with:
    • The game board boundaries (walls).
    • Its own body.

🧠 Code Insights (from main.cpp)

A brief look at the engine under the hood:

  • init_game(): Sets up the ncurses environment, initializes the game board, places the initial snake, and spawns the first piece of food.
  • draw_board(): Renders the playing area boundaries.
  • draw_snake() / draw_food(): Responsible for visually representing the snake and food on the terminal.
  • move_snake(): Updates the snake's position based on player input and current direction. This function also handles the logic for the snake's body following its head.
  • check_collision(): Detects if the snake has hit a wall or itself, triggering the game over state.
  • check_food_eaten(): Checks if the snake's head has reached the food. If so, it grows the snake and repositions the food.
  • game_over(): Displays the end-game message and awaits player action to close.
  • main(): The heart of the game, containing the main game loop that processes input, updates game logic, and refreshes the display.

✨ Future Enhancements & Creative Ideas

This classic can always learn new tricks! Here are some potential ideas:

  • 🏆 Scoring System: Keep track of points for each food eaten.
  • 🔥 Difficulty Levels: Introduce varying speeds or obstacles.
  • 🎨 Color Customization: Allow players to choose colors for the snake, food, or board.
  • 🚀 Power-ups: Special food items that grant temporary abilities (e.g., speed boost, invincibility, score multiplier).
  • 🧱 Obstacles: Add static or moving obstacles within the game board.
  • 🎵 Sound Effects: Basic beeps for eating or game over (if terminal supports).
  • High Score Board: Save and display top scores.
  • "Ghost Mode": Allow passing through walls to appear on the opposite side.

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page (if you plan to host this on GitHub/GitLab).

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(Optional: Add a License section here if you have one, e.g., MIT License)

About

A simple game written using C++ programming language and using the following libraries: windows.h time.h

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages