This is the extended version of the 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.
This project was extended within the C++ Nanodegree Program of Udacity following the learned principles.
The game was basically extended with a players and highscore list.
- All players together with their highscore are stored to a semicolon separated highscore.txt
- All players are loaded and printed to the console sorted by name together with an unique ID and highscore
- The user is asked to select a player by its ID or enter a name to create a new player
- The user can play the game. The active player is additionally shown in the title bar
- After the game is terminated, the user is informed if he beat her/his highscore
- The players list is saved back to the file together with the new highscore if beaten
- The players list is printed to the console sorted by highscore
- 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 code is clearly organized, grouped by functions and commented well. Same functionalities are wrapped to functions which are reused (e.g. addPlayer which is both used for creating a new player or loading the highscore.txt). Control structures are used to sort the players list or print the list nicely depending on the size of the names.
- Players' names and highscores are loaded from and saved to a txt file.
- The user can input an ID or name to select an existing user or create a new one.
- A new class player is created which stores ID, name and highscore of a single player and a static vector<> to hold all created players using addPlayer().
- The class uses private and public as needed. For instance, the static list is private to prevent manipulation.
- In the ctor, name and highscore are set using the setter() function to validate the data (e.g. max length for name of 15 and non-negative highscore). The setter() itself set the private members.
- Encapsulation is used for _id, _name and _highscore. _name and _highscore are validated on setting and _id is initialized interally.
- The project uses move semantics moving the shared_ptr into the list of players
- The project uses shared_ptr as the pointer are used from the list members by printing and saving, by the console when writing the new highscore and by the window in the title to show the player's name
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.