In this project, A grid based snake game is designed using C++ language and SDL(Simple DirectMedia Layer) Library. It is three levels having three different diffculty level. To move the snake we can use arrows(Left, Right, Up, and Down). Space key is used to pause and resume the game.
-
Point class uses template to define Point a point in 2-D
-
Animal class is Abstract class that is inherited by Snake and Rat class
-
Snake class represent the snake in Game
-
Rat class represent the food for snake in Game
-
Renderer class is used to render figures and texts
-
Game class contains main logic of the game, It contain mainLoop and levels of the game
Animal(Abstract class) / \ / \ Snake Rat
- cmake >= 3.14
- All OSes: click here for installation instructions
- make >= 4.1 (Linux, Mac), 3.81 (Windows)
- Linux: make is installed by default on most Linux distros
- Mac: install Xcode command line tools to get make
- Windows: Click here for installation instructions
- SDL2 >= 2.0
- All installation instructions can be found here
- Note that for Linux, an
apt
orapt-get
installation is preferred to building from source.
- SDL2_ttf >= 2.0
- All OSes: click here for installation instructions
- gcc/g++ >= 5.4
- Linux: gcc / g++ is installed by default on most Linux distros
- Mac: same deal as make - install Xcode command line tools
- Windows: recommend using MinGW
- Clone this repo.
- Make a build directory in the top level directory:
mkdir build && cd build
- Compile: cmake .. && make
- Run it: ./snake.
See the LICENSE file for license rights and limitations (MIT).
- for, while, if-else if-else, switch, do-while - Used in may files and many places(i.e. Game.cpp have do-while in line 217)
- User input - Game.cpp function - inputHandler
- OOP - Game.h, Point.h, Snake.h etc.
- Constructor with Member initilization list - Game.cpp, Snake.cpp etc.
- Abstract class - Animal.h
- Inheritance - Animal class is inherited by Snake and Rat classes
- Unique_ptr - Game.h for data member snake and rat line 14 and 15
- Template - Point.h
- Rule of 5 - Renderer.h
- Derived class functions override virtual base class functions - Snake.cpp and Rat.cpp And many more features are used in this program