DPontes / CppND-Capstone-Snake-Game

A 2D Snake game using C++ and SDL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CPPND: Capstone Snake Game

This project is cloned from 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.

This project was chosen due to the lack of time to complete it given the developer's situation.

1. Dependencies for Running Locally

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

3. Enhancements to the game

3.1. Added a Border around the Perimeter

An infinite world is rather boring, so a border around the perimeter was added as a new Border class. It is rendered as a green line, and if the snake goes into the border, the game finishes. The initial solution can be seen in the PR #32, although this PR contained a couple of errors later fixed in the PR #36.

Currently the algorithm consists of two for-loops that go through the top and bottom edges, and the side edges, respectively. There might be a better algorithm to do this, but this solution will do for now.

4. Project Requirements (Rubric)

The rubric for this project has been translated into Automated Github Issues which can be followed in the Project Kanban Board

4.1. README

4.1.1. A README with instructions is included in the project ✔️

  • This information can be found above in this README file

4.1.2. The README includes information about each rubric point addressed ✔️

  • Well, you're looking at it :)

4.1.3. The README indicates which project was chosen ✔️

  • Again, this information can be found above in this file

4.2. Loops, Functions and I/O

4.2.1. The project demonstrates an understanding of C++ functions and control structures

4.2.2. The project reads data from a file or writes data to a file

4.2.3. The project accepts user input and processes the input ✔️

  • The base code from Udacity's repository already includes the acceptance of user input to move the snake in the game.

4.3. Object Oriented Programming

4.3.1. The project used Object Oriented Programming techniques ✔️

  • The base code from Udacity's repository is already organized into classes, with attributes and methods.

4.3.2. Classes use appropriate access specifiers for class members ✔️

  • The base code from Udacity's repository already has the correct access specifiers in the existing classes; moreover, the new Border class in the border.h file also has the correct access specifiers

4.3.3. Class constructors utilize member initialization lists

4.3.4. Classes abstract implementation details from their interfaces ✔️

  • The base code from Udacity's repository already describes their effect through their names; moreover, the new Border class and it's members describe their effect through the name of the member functions.

4.3.5. Classes encapsulate behaviour

4.3.6. Classes follow an appropriate inheritance hierarchy

4.3.7. Overloaded functions allow the same function to operate on different parameters

4.3.8. Derived class functions override virtual base class functions

4.3.9. Template generalize functions in the project

4.4. Memory Management

4.4.1. The project makes use of references in function declarations

4.4.2. The project uses destructors appropriately ✔️

  • In PR #41 it was added the proper destructors to every class in the program.

4.4.3. The project uses Resource Aquisition Is Initialization (RAII) where appropriate

4.4.4. The project follows the Rule Of 5

4.4.5. The project uses move semantics to move, instead of copying, data (where possible)

4.4.6. The project uses smart pointers instead of raw pointers ✔️

  • In PR #45 it was introduced a smart pointer of the borderLine vector that is used inside the Snake::UpdateBody function

4.5. Concurrency

4.5.1. The project uses multithreading ✔️

  • The calling of the function PlaceFood() in Game::Update() is done with a thread:
  if (food.x == new_x && food.y == new_y) {
    score++;
    std::thread t(&Game::PlaceFood, this);     <--------
    // Grow snake and increase speed.
    snake.GrowBody();
    snake.speed += 0.02;
    t.join();                                  <--------
  }

4.5.2. A promise and future are used in the project

4.5.3. A mutex or lock is used in the project

4.5.4. A condition variable is used

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

About

A 2D Snake game using C++ and SDL

License:Creative Commons Attribution Share Alike 4.0 International


Languages

Language:C++ 75.2%Language:CMake 24.8%