This repository contains a simple command-line Snake Game implemented in C++. The game is designed for beginner programmers to learn about essential programming concepts such as arrays, loops, functions, enums, and game logic.
In this Snake Game:
- The player controls the snake's movement using the keyboard (
W,A,S,D). - The goal is to eat the fruit (
#) to grow the snake and increase the score. - The game ends if the snake collides with the wall or itself.
- A C++ compiler (e.g., Visual Studio, Code::Blocks, GCC, or any online compiler).
- (Optional) Git installed on your computer.
-
Clone the Repository
Open a terminal and run the following command:git clone https://github.com/sudipfgcu/programming1_snakegame.git cd snake-game-cpp -
Compile the Code
Use a C++ compiler to compile the code:g++ snake_game.cpp -o snake_game
-
Run the Game
Execute the compiled program:./snake_game
-
Play the Game
- Control the snake using the keyboard:
W: Move UpA: Move LeftS: Move DownD: Move Right
- Press
Xto exit the game.
- Control the snake using the keyboard:
- Simple ASCII graphics for easy visualization in the terminal.
- Adjustable difficulty levels:
- Easy
- Medium
- Hard
(Set at the beginning of the game.)
- Score tracking to compete with yourself or others.
This code demonstrates the following C++ concepts:
- Control Structures: Loops (
for,while), conditionals (if,switch). - Enums: Representing snake directions.
- Arrays: Managing the snake's tail.
- Functions: Game logic split into modular functions (e.g., rendering, input handling, updating game state).
- Console I/O: Using
coutandcinfor interactions. - Keyboard Input Handling: Using
_kbhit()and_getch()from<conio.h>. - Basic Graphics: Drawing walls, the snake, and food with ASCII characters.
- Manually change the height and width of the boundary to width = 100; height = 30;
- Make the snake’s tail grow by 2 units instead of 1 every time it eats a fruit.
- Change the side walls from '|' to 'L'
This project is open-source and free to use for educational purposes.
Developed as a class project to help students learn programming basics in C++.