This is the Capstone project in the Udacity C++ Nanodegree Program. The code for this repo was inspired by this excellent StackOverflow post and set of responses.
As we can see in the GIF below, the core of the game is kept as is.
-
Added Bonus Food (in green) that appears after eating 5 normal fruits for 10 seconds and increases the score without affecting the snake length.
-
Added Menu to the game screen
-
Added Leader Board of Top 5 records
-
Score is shown after the game is over
-
New Score is logged in the Leader board
- 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. - SDL2_ttf >= 2.0
- All installation instructions can be found here
Note that for Linux, an
apt
orapt-get
installation is preferred to building from source. Typical installation command for APT package manager issudo apt-get install libsdl2-ttf-dev
- 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
.
- C++ functions and control structures
- Functions and control structures can be found everywhere in the project.
- File Manipulation.
- File manipulations can be found in
LeaderBoard.c
where theLeaderBoard.txt
file is read from and written to.
- File manipulations can be found in
- The project uses data structures and immutable variables.
- Game has been restructured to be more SOLID which introduces new mutable and immutable structures for example in
IScreen.h
as well asutil.h
andutil.cpp
files.
- Game has been restructured to be more SOLID which introduces new mutable and immutable structures for example in
-
One or more classes are added to the project with appropriate access specifiers for class members.
- see
ScreenManager.h
,LeaderBoard.h
,util.h
,IScreen.h
,WelcomeScreen.h
- see
-
Class constructors utilize member initialization lists.
- see
ScreenManager.cpp
,LeaderBoard.cpp
,util.cpp
,WelcomeScreen.cpp
- see
-
Classes abstract implementation details from their interfaces.
- see
ScreenManager.h
&ScreenManager.cpp
as an example
- see
-
Overloaded functions allow the same function to operate on different parameters.
- see
Renderer::Render()
inrenderer.cpp
line 54 & 63
- see
-
Classes follow an appropriate inheritance hierarchy with virtual and override functions.
- See
ScreenManager.h
,GameScreen.h
andIScreen.h
- See
-
Templates generalize functions or classes in the project.
- See
IScreen.h
,ScreenManager.h
,GameScreen.h
andrenderer.h
- See
- The project makes use of references in function declarations.
- See
ScreenManager.h
functionScreenManager::Start()
.
- See
- The project uses destructors appropriately.
- See
Controller::~Controller()
inController.cpp
.
- See
- The project uses scope / Resource Acquisition Is Initialization (RAII) where appropriate.
- see
ScreenManager.cpp
,LeaderBoard.cpp
,util.cpp
,WelcomeScreen.cpp
member variable initialization and constructor overloads ofScreenItem
class inutil.h
.
- see
- The project uses move semantics to move data instead of copying it, where possible.
- See
MessageBox.h
.
- See
- The project uses smart pointers instead of raw pointers.
- See
_keyStrokes
MessageBox pinter incontroller.h
.
- See
- The project uses multithreading.
- See
controller.h
,controller.cpp
&GameScreen.cpp
- See
- A mutex or lock is used in the project.
- see
ScreenManager.cpp
,LeaderBoard.cpp
,util.cpp
,GameScreen.cpp
&WelcomeScreen.cpp
- see
- A condition variable is used in the project.
- see
MessageBox.h
&GameScreen.cpp
- see
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.