This is 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.
Rules:
- The user selects the difficulty level at the beginning: from 1 to 5.
- The higher the difficulty level, the faster the snake starts moving.
- The higher the difficutly level, more points you get by each meal eaten.
- 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
.
- The user can select a level of difficulty from 1 to 5. The more difficulty, the more the snake speed increases and more points earns for eating food. commit
- Snake speed is defined as private member in Snake, so Game must use "IncreaseSpeed" method to update its value. In that way, snake also controls its maximum speed set to 0.95. commit
- Composition: Snake class is allocated in heap as a smart pointer inside Game class: commit
- Composition: Conroller class is allocated in heap as a smart pointer inside Game class: commit
- Memory Management: SDL_WIindow and SDL_Renderer are stored as unique_ptr's inside Renderer: commit
- Fix bug regarding placing food out of right boundaries: commit
- Fix bug of snake moving to the opposite direction: commit
- README (All Rubric Points REQUIRED):
- A README with instructions is included with the project.
- The README indicates which project is chosen.
- The README includes information about each rubric point addressed.
- Compiling and Testing (All Rubric Points REQUIRED)
- The submission must compile and run.
- Loops, Functions, I/O
- The project demonstrates an understanding of C++ functions and control structures.
- The project reads data from a file and process the data, or the program writes data to a file.
- The project accepts user input and processes the input. --> User can select the level of difficulty: it is displayed in the window title and affects the increase of speed and points each time the snake eats food.
- Object Oriented Programming
- The project uses Object Oriented Programming techniques. --> Controller class is located inside Game in order to hide it from main and abstract.
- Classes use appropriate access specifiers for class members. --> Snake speed is updated through IncreaseSpeed method
- Class constructors utilize member initialization lists.
- Classes abstract implementation details from their interfaces. --> Snake hides to controller its last moved direction.
- Classes encapsulate behavior. --> Controller only forwards the direction to move, then snake decides if it is allowed or not by checking last direction moved.
- 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.
- Memory Management
- The project makes use of references in function declarations.
- The project uses destructors appropriately. --> Have set the proper destructors for SDL_Window and SDL_Renderer unique_ptr's, so no memory leaks.
- The project uses scope / Resource Acquisition Is Initialization (RAII) where appropriate. --> Smart pointers are used instead of raw pointers, which ise the RAII principle, deallocating memory as soon as their owner class goes out of scope.
- The project follows the Rule of 5. --> We construct the Render inside of Game by using move constructor.
- The project uses move semantics to move data, instead of copying it, where possible. --> When defining the level of difficulty in main, the value is passed to Game() class as it is not more useull inside main.
- The project uses smart pointers instead of raw pointers. --> Snake, Controller are allocated in heap and have smart pointers pointing to theme inside Game class. Also SDL_Window and SDL_Renderer inside Renderer.
- Concurrency
- The project uses multithreading.
- A promise and future is used in the project.
- A mutex or lock is used in the project.
- A condition variable is used in the project.