This starter repo for the Capstone project in the Udacity C++ Nanodegree Program was added with a few features mentioned in the section below. The code for this repo was inspired by this excellent StackOverflow post and set of responses.
The following features have been added to the game:
-
Bonus Food Object: A bonus food object now appears whenever the player's score is greater than 0 and is a multiple of 10. The bonus food object grants extra points when collected and decreases the speed of the snake, adding a new challenge to the game.
-
Timer for Bonus Food: The bonus food object has a limited appearance time of 10 seconds. After this time, the bonus food disappears from the game.
-
Restart Option: When the game is over, a pop-up window appears with an option to restart the game. Players can restart the game by clicking on the "OK" button in the pop-up window.
-
Score Recording: The game now keeps track of the player's score and saves it to a text file. This allows players to review their progress and high scores even after closing the game.
- 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
.
Success Criteria | Specifications | Usage in Code |
---|---|---|
The project demonstrates an understanding of C++ functions and control structures. | - A variety of control structures are used in the project. - The project code is clearly organized into functions. - The project reads data from a file and processes the data, or the program writes data to a file. - The project accepts user input and processes the input. |
- Control structures used through out the code. - Functions are used through out the code. - Game scroe is written to a text file at when the game is closed. - User input processed for controlling the snake. |
Success Criteria | Specifications | Usage in Code |
---|---|---|
The project uses Object-Oriented Programming techniques. | - The project code is organized into classes with class attributes to hold the data, and class methods to perform tasks. - Classes use appropriate access specifiers for class members. - Class constructors utilize member initialization lists. - Classes abstract implementation details from their interfaces. - Classes encapsulate behavior. - Classes follow an appropriate inheritance hierarchy. - Overloaded functions allow the same function to operate on different parameters. - Derived class functions override virtual base class functions. - Templates generalize functions in the project. |
- The code uses Classes through out. - Access specifiers are used in the classes. - Member initialization lists are used through out the classes. - All the classes hide implementation. - Behavior encapsulated in all the classes. - Inheritance hierarchy used in the Snake class as it inherits from GameObject class. - Overloaded function Reset in class Snake. - Virtual function Reset override in class Snake. - WriteToFile Function uses template in the main.cpp file. |
Memory Management | - The project makes use of references in function declarations. - The project uses destructors appropriately. - The project uses scope / Resource Acquisition Is Initialization (RAII) where appropriate. - The project follows the Rule of 5. - The project uses move semantics to move data, instead of copying it, where possible. - The project uses smart pointers instead of raw pointers. |
- References used wherever required, example : in the parameters in the Run function of the class Game. - Destructor used in class Renderer for proper memory release. - RAII pattern applied in the smart pointer used for sdl_render. - Rule of 5 implemented in class Renderer. - Move semantics used in function RunGame in the main.cpp. - Smart pointer used in class Renderer. |
Concurrency | - The project uses multithreading. - A promise and future are used in the project. - A mutex or lock is used in the project. - A condition variable is used in the project. |
- Multithreading used to run the BonusFoodTimer in a seperate thread in the Game Class. - Promise and future used in the main function to get GameResult. - Mutex and unique_lock used in the Game Class methods to protect shared data is_bonus_food_active. - Condition variable in function Update of Game class for thread synchronization. |
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.