Reinventing the good old first experiences with computers :-)
This is an implementation of the game "Snake", under construction for the Capstone project in the Udacity C++ Nanodegree Program. The code in this repo is based on a "starter repo" provided by Udacity which in turn was inspired by this excellent StackOverflow post and set of responses.
The Capstone Project concerned the integration of learnings throughout this program.
Here, I will list and describe the changes I made to complete this project:
-
Update this README.md to reflect current repository content. While listed first, this reflects an activitiy that I try to continuously iterate in sync with the changes I make.
-
Implemented some simple bug and style fixes:
- Food placement in the original code could be outside the visible area because placement occured in a space that was 1 "block" wider and higher than the define gridwidth and gridheight.
- The object Snake is passed to the Renderer object by const reference instead of const value to prevent the program from creating a copy of the object.
- The initialization order for the Snake constructor is changed to resemble the declaration order of variables.
- The initialization for the Snake constructor involved an implicit int to float conversion, which is now made explicit.
-
Added Player and Menu classes, respectively holding functionality to maintain a highscore record and to provide a user prompt asking for player name at the start of the game.
-
Refined the Player class to compare result with previous results in case they exist, and to bring some extra reward to those that end up in the top 3.
-
Implemented a wall around the playable area that can't be crossed.
Main.cpp instantiates 4 objects:
- Menu (the object that asks the player to enter a name)
- Renderer (the object that renders the actual playing screen)
- Controller (the object that handles userinput while playing the game)
- Game (Updating the steps in the game loop) * This class also instantiates a Snake and a Player object respectively holding the functionality related to snake position and the functionality related to scoring the players performance.
- All criteria related to "Loops, Functions and I/O"
- The first five criteria related to "Object Oriented Programming"
- The first two criteria related to "Memory Management"
- 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
.