This game was developed from a starter repo for 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.
Basic game functionality has been extended as follows:
- The actual game is wrapped in a menu loop. Upon running the executable, a menu is shown in the terminal. The user then selects the desired menu option.
- Existing game mode (i.e. one blue-headed user-controlled snake) is deemed as Simple game mode. Now there is also an Advanced game mode, where the user-controlled snake and one magenta-headed autonomous snake go after the same food. The autonomous snake is driven using the A* algorithm, and avoids moving over board edges.
- The game keeps track of top 10 high scores regardless of game mode (i.e. both modes share the same high score data).
- 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
.
This project uses multiple modern C++ features and paradigms:
- Reading and writing data from an external file.
- Using data structures such as arrays and vectors, as well as constant variables and constant function parameters.
- Function overloading with different signatures for the same function name.
- Inheritance hierarchies with virtual base class member function overriding and runtime polymorphism.
- Function templates.
- Passing variables by references (example 1, example2).
- Freeing up unmanaged dynamically allocated memory using a destructor.
- Using std::move as one aspect of move semantics.
- Smart pointers and RAII (Resource Acquisition Is Initialization) pattern.
- Multithreading.
- Promise/future pattern.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.