Skip to content

Sputnik24/CppND-Capstone-Snake-Game

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPPND: Capstone Snake Game Example

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.

New Features

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

Dependencies for Running Locally

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.

Rubric Points

Loops, Functions, I/O

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

OOP

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

Memory Management

  • 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

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 79.4%
  • CMake 20.6%