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.
- 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
.
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.
The rubric for this project has been translated into Automated Github Issues which can be followed in the Project Kanban Board
- This information can be found above in this README file
- Well, you're looking at it :)
- Again, this information can be found above in this file
- The base code from Udacity's repository already includes the acceptance of user input to move the snake in the game.
- The base code from Udacity's repository is already organized into classes, with attributes and methods.
- The base code from Udacity's repository already has the correct access specifiers in the existing classes; moreover, the new
Border
class in theborder.h
file also has the correct access specifiers
- 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.
- 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
- In PR #45 it was introduced a smart pointer of the
borderLine
vector that is used inside theSnake::UpdateBody
function
- The calling of the function
PlaceFood()
inGame::Update()
is done with athread
:
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(); <--------
}
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.