Skip to content

yuta-imai/CppND-Capstone-Snake-Game

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPPND: Capstone Snake Game Example

This is a my Capstone project in the Udacity C++ Nanodegree Program. The code for this repo was inspired by this excellent StackOverflow post and set of responses.

Work summary

In my project, I made food randomly update its location so the game gets more exciting. To achieve this, I add Food class which manages its location and performs random location update by using a thread.

Work in detail

  • main.cpp: Made it to write result to a file, not only console.
  • Snake: Added IsAlive() and PoisonPill() so we can observe if its alive and let it die without touching member vaiables directly.
  • Food: As mentioned in summary, this is a representation of food, which manages its location and performs random location update by using a thread.
  • Controller: Now you can terminate game by ESC key.

vs. Rubrics

README

  • Has README which describes project and work.

Compiling and Testing

  • It compiles.

Loops, Functions, I/O

  • It writes result to a file.
  • The project accepts arrow keys and ESC key.

Object Oriented Programming

  • The project uses object oriented programming techniques.
  • For Snake class, it encapsulates private members and provides clearer methods than having accessed members directly.

Memory Management

  • The project uses smart pointer shared_ptr to share Snake object among Game and Food.

Concurrency

  • The project uses thread inside Food to run random update of its location.
  • For safe access to Food members from main game thread and thead inside Food, the project uses std::mutex and std::lock_guard.

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.

About

A 2D Snake game using C++ and SDL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 76.6%
  • CMake 23.4%