/CPPND-Capstone-Snake-Game

Primary LanguageC++Creative Commons Attribution Share Alike 4.0 InternationalCC-BY-SA-4.0

CPPND: Capstone Snake Game

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.

Added Features

The following features have been added to the game:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

Dependencies for Running Locally

Basic Build Instructions

  1. Clone this repo.
  2. Make a build directory in the top level directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./SnakeGame.

Rubric followed

Loops, Functions, I/O

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.

Object-Oriented Programming

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.

CC Attribution-ShareAlike 4.0 International

Shield: CC BY-SA 4.0

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

CC BY-SA 4.0