git clone --recurse-submodules
make init_env
make build_debug
./build/SnakeGame
All points indicate at least one place in the code, but it is obvious that almost all clauses appear more than once in the code.
- The project demonstrates an understanding of C++ functions and control structures.
- while:
game.cpp
line 15void Game::Run()
- if:
game.cpp
line 31void Game::Update()
- else if:
controller.cpp
line 12void Controller::HandleInput(bool &running, const std::unique_ptr<GameStateManager>& state_manager)
- switch:
gamefield_factory.cpp
line 13std::unique_ptr<GameField> GameFieldFactory::CreateGameField(const GameStateType type)
- case:
gamefield_factory.cpp
line 15, 21, 28std::unique_ptr<GameField> GameFieldFactory::CreateGameField(const GameStateType type)
- default:
gamefield_factory.cpp
line 35std::unique_ptr<GameField> GameFieldFactory::CreateGameField(const GameStateType type)
- return:
gameplay-manager.cpp
line 18void GamePlayManager::ChangeState(const GameStateType nextStateType)
- for:
player_game_field.cpp
line 93Winner PlayerGameField::GetWinner()
- continue:
a_star_async.cpp
line 113ResultCell AStartAsync::AStarSearch(Cell* const start, const Cell* const goal)
- break:
main_menu_state.cpp
line 21, 24, 27, 30, 33void MainMenuState::HandleScreenEvent(const MainMenuEvent event)
- while:
- The project reads data from a file and process the data, or the program writes data to a file.
- read from file:
game_save_data.cpp
line 9, 10void Game::LoadBestScore()
- write to file:
game_save_data.cpp
line 52, 53void Game::SaveData()
- read from file:
- The project accepts user input and processes the input.
- user keyboard input:
single_player_state.cpp
line 21, 22void SinglePlayerGameState::HandleInput(const SDL_Keycode keyCode)
- user mouse input:
multiplayer_screen.cpp
line 44, 49, 54void MultiplayerGameScreen::Render()
- user keyboard input:
- The project uses data structures and immutable variables.
- data structures:
a_star_async.hpp
line 61std::vector<std::vector<Cell*>> grid_{};
- immutable variables:
a_star_async.hpp
line 34:void calculateHeuristic(const Cell* const goal)
- data structures:
- One or more classes are added to the project with appropriate access specifiers for class members.
- class attributes:
game_field.hpp
line 37-41 - class methods:
gameplay_manager.hpp
line 23-26
- class attributes:
- Class constructors utilize member initialization lists.
- member initialization:
player_game_field.cpp
line 8-10PlayerGameField::PlayerGameField(std::size_t gridWidth, std::size_t gridHeight)
- member initialization:
- Classes abstract implementation details from their interfaces.
- class interface:
game_state_manager.hpp
line 26-29 - expected behavior:
game_states.hpp
line 58, 64, 70
- class interface:
- Classes follow an appropriate inheritance hierarchy with virtual and override functions.
- inheritance, polymorphism:
game_field.hpp
line 20-27
- inheritance, polymorphism:
- Templates generalize functions or classes in the project.
- template class:
screen.hpp
line 19, 20
- template class:
- The project makes use of references in function declarations.
- reference arg:
game_states.hpp
line 58void Render(SDL_Renderer *sdl_renderer, SDL_Rect& block)
- reference arg:
a_star_async.hpp
line 58ResultCell AStarSearch(Cell* const start, const Cell* const goal)
- reference attr:
renderer.h
line 19, 20
- reference arg:
- The project uses destructors appropriately.
- destructor:
a_star_async.cpp
line 21-29AStartAsync::~AStartAsync()
- destructor:
- The project uses scope / Resource Acquisition Is Initialization (RAII) where appropriate.
- allocating:
a_star_async.cpp
line 15AStartAsync::AStartAsync(const std::size_t gridWidth, const std::size_t gridHeight)
- initializing:
a_star_async.cpp
line 41, 42void AStartAsync::FindPathAsync(int startX, int startY, const CellType goalCellType, const std::unordered_map<std::size_t, std::unordered_map<std::size_t, CellType>>& field)
- destruction:
a_star_async.cpp
line 24AStartAsync::~AStartAsync()
- allocating:
- The project follows the Rule of 5.
- operators, constructors, destructor:
a_star_async.hpp
line 42-48
- operators, constructors, destructor:
- The project uses move semantics to move data instead of copying it, where possible.
- move semantic:
game_states.cpp
line 15, 16void GameStateBase::MoveGamePlayManager(std::unique_ptr<GamePlayManager>&& manager)
- move semantic:
- The project uses smart pointers instead of raw pointers.
- unique_ptr:
game_states.hpp
line 77
- unique_ptr:
- The project uses multithreading.
- multithreading:
a_star_async.cpp
line 51void AStartAsync::FindPathAsync(int startX, int startY, const CellType goalCellType, const std::unordered_map<std::size_t, std::unordered_map<std::size_t, CellType>>& field)
- get result:
a_star_async.cpp
line 71ResultCell AStartAsync::GetResult()
- multithreading:
All libraries install with vcpkg. The project uses the following libraries:
- SDL2
- ImGui
- nlohmann json
Game has the three modes:
- Single player
- Player vs Player
- Player vs AI Player
Control the snake with the arrow keys. The snake will grow when it eats the food. The game ends when the snake collides with itself.
Control the first snake with the arrow keys and the second snake with the WASD keys. The snakes will grow when they eat the food. The game ends when one of the snakes collides with itself or the other snake.
Control the snake with the arrow keys. The snake will grow when it eats the food. The game ends when the snake collides with itself or the AI snake.
If snake collides with the other snake, the game will end and despite the score of the collides snake it will lose.
- Arrow keys: Move the snake (all game modes)
- WASD keys: Move the second snake (PvP game mode)
- P, Esc: Pause the game (all game modes)
- Added the new game modes
- Added the AI player
- Added the UI
- Added the best score save/load for all game modes
This is a 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.
The Capstone Project gives you a chance to integrate what you've learned throughout this program. This project will become an important part of your portfolio to share with current and future colleagues and employers.
In this project, you can build your own C++ application or extend this Snake game, following the principles you have learned throughout this Nanodegree Program. This project will demonstrate that you can independently create applications using a wide range of C++ features.
- 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
.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.