Retro_Gameboy
The purpose of this project is to create a GameBoy with classic games.
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Pages
Data Structures | Public Member Functions | Private Member Functions | Private Attributes
Snake Class Reference

#include <Snake.h>

Inheritance diagram for Snake:
Inheritance graph
[legend]
Collaboration diagram for Snake:
Collaboration graph
[legend]

Data Structures

struct  Fruit
 Structure to holds x and y cordinates of the fruit. More...
 
struct  SnakeStrct
 Structure to holds x and y cordinates of the snake when it move across the grid. More...
 

Public Member Functions

 Snake ()
 Default Constructor. initialize variables. More...
 
virtual int CalculateScore ()
 Pure virtual function inherited from GameGenerics.h Each game calculate scores differently and therefore this function need to override in each game according to the game rules. More...
 
- Public Member Functions inherited from GameGenerics
 GameGenerics ()
 Default Constructor for GameGenerics. This is a abstract class and you cannot instantiate this class. More...
 

Private Member Functions

void InitializeVars ()
 Create Sprites. Load the Images and set the Sprites. Call PlaySnake() function to start the game. More...
 
void MoveSnake ()
 Move Snake across the grid per Tick. More...
 
void MoveToThisDirection ()
 Set the direction to move the snake. 0 indicates down. 3 indicates up. 1 indicates left. 2 indicate right. More...
 
void BoundaryControl ()
 If snake cross the boundary of the window make it reappear on the opposite side of the window. More...
 
void GrowUponEat ()
 Whenever snake eats a fruit make it grow by 1 square. More...
 
void KeyControls ()
 Allow user to control snake by using arrow keys. More...
 
void DrawSprites (RenderWindow &window, Sprite &sprite1, Sprite &sprite2)
 Draw sprites on the window. More...
 
void GameOverLogic ()
 Whenever snake tries to eat itself game is over. More...
 
void PlaySnake (RenderWindow &window, Sprite &sprite1, Sprite &sprite2)
 Start the game. More...
 

Private Attributes

const int N = 30
 Define length with 30 squares. More...
 
const int M = 20
 Define height with 30 squares. More...
 
const int SIZE = 16
 Define space between each square. More...
 
const int WIDTH = SIZE * N
 Define width of the window. More...
 
const int HEIGHT = SIZE * M
 Define height of the window. More...
 
int m_direction
 Direction of the snake. More...
 
int m_SnakeLength
 Length of the snake. More...
 
int m_Score
 Track game score. More...
 
bool m_IsGameOver
 Track when game is over or not. More...
 
Fruit m_MyFruit
 Holds x and y cordinates of the snake when it move across the grid. More...
 
SnakeStrct m_MySnake [100]
 Holds x and y cordinates of the fruit. More...
 

Additional Inherited Members

- Protected Member Functions inherited from GameGenerics
void GameOverScreen (RenderWindow &window)
 Display a game over screen at the end of the game alone with user's score. Currently, every game has the same game over screen. If each and every game needs a different screen, it might be a good idea to make it a pure virtual function. More...
 

Detailed Description

Definition at line 6 of file Snake.h.

Constructor & Destructor Documentation

◆ Snake()

Snake::Snake ( )

Default Constructor. initialize variables.

Definition at line 3 of file Snake.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ BoundaryControl()

void Snake::BoundaryControl ( )
private

If snake cross the boundary of the window make it reappear on the opposite side of the window.

Definition at line 70 of file Snake.cpp.

Here is the caller graph for this function:

◆ CalculateScore()

int Snake::CalculateScore ( )
virtual

Pure virtual function inherited from GameGenerics.h Each game calculate scores differently and therefore this function need to override in each game according to the game rules.

Implements GameGenerics.

Definition at line 27 of file Snake.cpp.

◆ DrawSprites()

void Snake::DrawSprites ( RenderWindow &  window,
Sprite &  sprite1,
Sprite &  sprite2 
)
private

Draw sprites on the window.

Definition at line 139 of file Snake.cpp.

Here is the caller graph for this function:

◆ GameOverLogic()

void Snake::GameOverLogic ( )
private

Whenever snake tries to eat itself game is over.

Definition at line 48 of file Snake.cpp.

Here is the caller graph for this function:

◆ GrowUponEat()

void Snake::GrowUponEat ( )
private

Whenever snake eats a fruit make it grow by 1 square.

Definition at line 59 of file Snake.cpp.

Here is the caller graph for this function:

◆ InitializeVars()

void Snake::InitializeVars ( )
private

Create Sprites. Load the Images and set the Sprites. Call PlaySnake() function to start the game.

Definition at line 8 of file Snake.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ KeyControls()

void Snake::KeyControls ( )
private

Allow user to control snake by using arrow keys.

Definition at line 116 of file Snake.cpp.

Here is the caller graph for this function:

◆ MoveSnake()

void Snake::MoveSnake ( )
private

Move Snake across the grid per Tick.

Definition at line 33 of file Snake.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MoveToThisDirection()

void Snake::MoveToThisDirection ( )
private

Set the direction to move the snake. 0 indicates down. 3 indicates up. 1 indicates left. 2 indicate right.

Definition at line 93 of file Snake.cpp.

Here is the caller graph for this function:

◆ PlaySnake()

void Snake::PlaySnake ( RenderWindow &  window,
Sprite &  sprite1,
Sprite &  sprite2 
)
private

Start the game.

Definition at line 165 of file Snake.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ HEIGHT

const int Snake::HEIGHT = SIZE * M
private

Define height of the window.

Definition at line 24 of file Snake.h.

◆ M

const int Snake::M = 20
private

Define height with 30 squares.

Definition at line 15 of file Snake.h.

◆ m_direction

int Snake::m_direction
private

Direction of the snake.

Definition at line 27 of file Snake.h.

◆ m_IsGameOver

bool Snake::m_IsGameOver
private

Track when game is over or not.

Definition at line 36 of file Snake.h.

◆ m_MyFruit

Fruit Snake::m_MyFruit
private

Holds x and y cordinates of the snake when it move across the grid.

Definition at line 55 of file Snake.h.

◆ m_MySnake

SnakeStrct Snake::m_MySnake[100]
private

Holds x and y cordinates of the fruit.

Definition at line 58 of file Snake.h.

◆ m_Score

int Snake::m_Score
private

Track game score.

Definition at line 33 of file Snake.h.

◆ m_SnakeLength

int Snake::m_SnakeLength
private

Length of the snake.

Definition at line 30 of file Snake.h.

◆ N

const int Snake::N = 30
private

Define length with 30 squares.

Definition at line 12 of file Snake.h.

◆ SIZE

const int Snake::SIZE = 16
private

Define space between each square.

Definition at line 18 of file Snake.h.

◆ WIDTH

const int Snake::WIDTH = SIZE * N
private

Define width of the window.

Definition at line 21 of file Snake.h.


The documentation for this class was generated from the following files: