Giter VIP home page Giter VIP logo

snakegame's Introduction

CPPND: Capstone Snake Game Example

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.

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.

Additional function made by student: Mingqi

  1. Short period of time of loading game at beginning before game start
  2. A command line for user to slect a game difficulty level 1 - 3, i.e. hard level will have more toxic food
  3. Toxic food with white color added to game: it will kill snake once snake hit it
  4. And boost food: it flashes in betwween green and red color
  5. Add toggling status to change status of boost:
    • green will reward a lot on score but speed up alot snake as well
    • red will reward a little on score, speed up a little as well
  6. Add toxic food:
    • Amont of toxic food depends on the difficulty level from user input
    • toxic foods are imeplemented through smart pointers, added one by one to the game
  7. User can hit B to add border to the outside, snake dies once hit; hit B again will cancel the border.
  8. highest score will be record on the txt file, each time player reach new record, system will congrats to user.
  9. User can hit ESC to pause the game, hit ESC again to resume the game.
  10. When user resume the game, snake remember its last direction before the pause and resume move on that direction

Rubric Points completed by student: Mingqi

  1. Loops, Functions, I/O: The project code extensively use "for", "while loop" at different places (e.g. invalid user input of game difficulty level, adding toxic food and cycle the boost food). Functions mostly pass by reference to prevent copy paste on the backend of the system. Code clearly organized into functions and classes. All reusable functions implemented as methods inside their class.

Project accept user inputs at the beginning or during the game, these inputs include pause or resume the game and choose a difficulty level. User can also hit B to add or cancel border to the game when game is running, which will make game even tougher/ A command line for utser to slect a game difficulty level, i.e. hard level will have more toxic food; These keyboard related functions are completed mostly in the game.cpp and render.cpp

  1. Object Oriented Programming - Classes use appropriate access specifiers for class members and their constructors utilize member initialization lists.

The project code added some new classes with attributes and methods to perform tasks and to hold the data: Some of class, structure, enum and funcions are written inside the files of toxic.h toxic.cpp menu.h menu.h, which have been used mostly by game or controller class. The constructor of these new class are added and have been make sure to get initialized properly. All class commute internal or each other with their functionality once needed, also all class data members are specified with public or private.

Under game.h game.cpp render.h render.cpp snake.h snake.cpp. many new methods and properties have been added to be able to perform the new capability lists aboved inside additional function.

  1. Memory Management Again, The project pass references in function declarations have been used in most of the cases to save from copy-paste. Both references and pointers are used a lot espeically on the new game object of toxic food and boost. The toxic food class adds smart pointer: unique_ptr<std::vector> _coords inside _toxic.h: when called by game constrcutor to intilize and render, those toxic food spawn one by one to the game. Depend based on its vector size > 0 or not, system will prompt a warning to user not to eat toxic food with white color. We can clearly observe the instance been destrcuted automatically once I placed a printout inside its destructor, the magic of RAII.

  2. Concurrency At the beginning of the game, system use a thread to wait for a short time to wait for game loading; The boost food creates a thread to loop the light status in between red and green. This thread waits for 1 - 3 seconds each light pahs and toggle its state to the othe light once the elapsed time has pass the threshold inside the thread.

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

snakegame's People

Contributors

smiky0403 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.