(I chose "CPPND : Capstone Snake Game" as a base project.)
In this game, you control a snake and guide it to a food. Yellow food is good for the snake, and the snake gets longer if the snake eats it. Red food is toxic, so the snake dies if the snake eats it.
- cmake >= 3.7
- 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. - 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:
./SnakeGame
.
-
Control a snake and get a yellow food.
-
If the snake eats a yellow food, the snake gets longer, score increases, and the number of toxic food increases.
-
If the snake eats a red food, the snake dies and Game is over, because it is a toxic food.
-
How to control the snake : Use arrow keys.
-
Push "p" key to Pause the game, and push "r" key to Resume(Re-start) the game.
I added or modified the features described below.
-
Added Food class Rubric point in this item :
- The project uses Object Oriented Programming techniques. and Classes encapsulate behavior. Defined Food class to have some attributes. (e.g. Food.attr, Food.position)
- Classes use appropriate access specifiers for class members. Added some public functions to access class members in Food. void SetPosition(int x, int y); bool CheckIfFoodIsThere(int x, int y); SDL_Point GetPosition(); bool CheckFoodIsToxic();
- Class constructors utilize member initialization list Utilized member initialization lists for the private member "attr".
- The project makes use of references in function declarations. To access "Food vector elements" from "Renderer::Render()" function, passed "&food" as a reference.
-
Added GameState class -> by this, player can pause/resume the game Rubric point in this item :
- The project accepts user input and processes the input. ("p" for pause, and "r" for resume the game)
- The project makes use of references in function declarations. To access "current_state" in "GameState" class from "Controller::HandleInput()" function, passed "GameState &state" as a reference.
- Class constructors utilize member initialization lists. Utilized member initialization lists for the private member "current_state" in GameState class.
-
Increased number of food Rubric point in this item :
- The project demonstrates an understanding of C++ functions and control structures. Defined "std::vector food", and used "for ( auto f : food )" control structure in "Game::PlaceFood()" and "Game::Update()" and "Renderer::Render()".
-
Added different type of food (Toxic food)
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.