Skip to content

minwang-ai/CppND-Capstone-Snake-Game

Repository files navigation

CPPND: Capstone Snake Game Example

This is 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.

New Features

  1. Player

    • Enter player name before game starts
    • Display player information after game over
    • File: player.h
  2. Thread-safe Moving Obstacle

    • Moving obstacle that travels horizontally across the screen
    • Game over when snake collides with obstacle
    • File: obstacle.h/cpp

Code Structure

  • main.cpp: Program entry, initializes game
  • controller.h/cpp: Input handling
  • game.h/cpp: Core game logic
  • renderer.h/cpp: Game rendering
  • snake.h/cpp: Snake movement and growth
  • obstacle.h/cpp: Moving obstacle implementation
  • player.h/cpp: Player info management

Dependencies for Running Locally

Basic Build Instructions

  1. Clone this repo: git clone <url>
  2. Make a build directory in the top level directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./SnakeGame.

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

Rubric Points Addressed

Loops, Functions, I/O (meet 2 criteria)

  • functions and control structures.
  • accepts user input and processes the input (main.cpp, lines 7-12)

Object Oriented Programming (meet 3 criteria)

  • two classes are added to the project with appropriate access specifiers for class members (obstacle.h/.cpp, player.h)
  • Class constructors utilize member initialization lists (obstacle.cpp, lines 3-8, player.h, lines 7-13)
  • Classes abstract implementation details from their interfaces.

Memory Management (meet 4 criteria)

  • use references (player.h, lines 12, game.cpp, lines 97, renderer.cpp, lines 41).
  • use destructors appropriately (obstacle.cpp, lines 10)
  • use scope / Resource Acquisition Is Initialization (RAII) where appropriate (std::lock_guard).
  • use move semantics to move data instead of copying it, where possible (player.h, lines 9).

Concurrency (meet 2 criteria)

  • use multithreading
    • Obstacle movement runs in separate thread (obstacle.cpp, lines 56)
  • use mutex and lock
    • Position protection with mutex (obstacle.cpp, lines 22)
    • Thread-safe position updates (obstacle.cpp, lines 37)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •