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.
In this project, I used what I learnt in the C++ Nanodegree to extend the Snake game.
- Obstacles:
- Obstacles are now part of the game and are added to the board every time the snake eats food.
- Game modes:
The game comes with 4 possible modee, which are selected in the console before the game initializes. The modes are:
- 1: Classic Snake
- 2: Snake With Static Obstacles
- 3: Snake with randomly moving obstacles
- 4: Snake with Obstacles that chase the head of the snake round the 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. - 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
.
- Project accepts user input to determine game mode
- Project is organised into functions.
- Project uses arrays, vectors and constant variables.
- All functions within classes have their purpose and function documented.
- Project is organized into classes, with
- Constructor and destructor of the game class have been expanded.
- Destructor of the game class is used to tidy up threads.
- References are called to manage implementation of obstacles vector and manage the threads.
- Snake is implemented as a unique pointer.
- Project splits the snake and the obstacle movement into two threads and runs them concurrently.
- Mutex and a lock is used for this, as is a conditional variable.