Abdelbary / SnakeGame-Cpp

2D snake game in c++ using SDL library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CPPND: Capstone Snake Game Example

The code for this repo was inspired by this excellent StackOverflow post and set of responses.

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.

Game Play

  • The game has three different feeding points a normal, shrink ,killer.
  • Normal feed point grow the snake by one cell and increase it's speed.
  • Shrink feed point shring the snake back to one cell size and restore it's defult speed.
  • For each shrink feeding point taken by the player a premenent killer point will be placed on the play board.
  • If the player eaten any of the killer red points instant death is the result.
  • If the player hit his body with his head instant death is the result.
  • When the game ends it store the final score to scores file and retrieve the highest score from that file and print it in terminal

File and Class Structure

There are 5 classes in My Submitted implementation.

class name Purpose
Controller Interact with users, let users use keyboard to control the snake in the game.
Game Game class stores the state in the game, the function object run has the game run in loops til end.
Renderer render the game to the screen.
Snake contains attributes to keep track of the Snake speed, size, and location.
Logger Read, Write and print the history record for players.

About

2D snake game in c++ using SDL library


Languages

Language:C++ 35.3%Language:Makefile 29.3%Language:CMake 19.1%Language:C 16.3%