Snoke
Snake Class Reference

Describes the Snake entity of the game. More...

#include <snake.h>

Collaboration diagram for Snake:

Public Member Functions

bool init (Point begin, short direction, int length)
 Initializes snake as an entity without ancoring it anywhere. More...
 
void setScheme ()
 
void getCoords (std::list< Point > *currBody)
 The method to get the snake whole body coordinates(x ,y) without giving the direct access. More...
 
Point getHeadCoords ()
 The method to get the coordinates(x, y) of the snake's head without giving the direct access. More...
 
bool setDirection (int dir)
 The method to set the direction where the snake is heading. More...
 
short getDirection ()
 The method to get the current direction without giving the direct access. More...
 
bool move (Labyrinth *labyrinth)
 The snake movement on the game field(should be called in each iteration of the game cycle, unless the snake is 'dead') More...
 

Private Member Functions

short checkIntersection (Point check, Labyrinth *laryrinth)
 Checking the given point for intersections with Ball, borders, obstacles. More...
 
short checkWisely (Point coords, Point bcoords)
 If the Point of the labyrinth we are checking is not free then decide the type of collision. More...
 
void moveHead (Point p, Change *change)
 Moving snake head to a described by parameters position and updating the addition to the labyrinth. More...
 
void moveBack (Point p, Change *change)
 Checking if we need to remove the back of the snake from the labyrinth(we don't in case it has eaten the Ball) More...
 

Private Attributes

short direction
 
std::list< PointStylestyle
 
std::deque< PointsnakeBody
 

Detailed Description

Describes the Snake entity of the game.

Parameters
direction- current direction where the snake is heading
style- array, which describes how should the snake be colored
snakeBody- deque type array, containing positions of snake's body segments

Definition at line 79 of file snake.h.

Member Function Documentation

short Snake::checkIntersection ( Point  check,
Labyrinth labyrinth 
)
private

Checking the given point for intersections with Ball, borders, obstacles.

Parameters
check- a Point to check
labyrinth- 2-dimensional array defying current state of every point of the game field (blocked or not)
ball- a pointer to a Ball object(to check intersection with)
Returns
- type of collision

Definition at line 248 of file snake.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

short Snake::checkWisely ( Point  check,
Point  bCoords 
)
private

If the Point of the labyrinth we are checking is not free then decide the type of collision.

Parameters
check- Point we are checking for type of a collision
bCoords- Point, containing the coordinates of the Ball
Returns
- type of the collision

Definition at line 264 of file snake.cpp.

Here is the caller graph for this function:

void Snake::getCoords ( std::list< Point > *  currBody)

The method to get the snake whole body coordinates(x ,y) without giving the direct access.

Parameters
currBody- an array where the current snake body is copied

Definition at line 331 of file snake.cpp.

Here is the caller graph for this function:

short Snake::getDirection ( )

The method to get the current direction without giving the direct access.

Definition at line 313 of file snake.cpp.

Point Snake::getHeadCoords ( )

The method to get the coordinates(x, y) of the snake's head without giving the direct access.

Definition at line 321 of file snake.cpp.

Here is the caller graph for this function:

bool Snake::init ( Point  begin,
short  dir,
int  length 
)

Initializes snake as an entity without ancoring it anywhere.

Parameters
begin- starting Point of a snake(where the tail segment will be situated)
dir- direction of snake's 'growth' as well as it's starting direction
length- the length of a 'new born' snake
Returns
- mark of whether the snake is successfully initialized

Definition at line 20 of file snake.cpp.

Here is the caller graph for this function:

bool Snake::move ( Labyrinth labyrinth)

The snake movement on the game field(should be called in each iteration of the game cycle, unless the snake is 'dead')

Parameters
labyrinth- the current state of the labyrinth object for intersection checking
ball- a pointer to a Ball object(to check intersection with)
change- 2-dimensional array of changes needed to be applied to the labyrinth
changeSize- max(len(change[0]), len(change[1])))
Returns
- mark of whether there was a non-boundary non-ball collision

Definition at line 80 of file snake.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Snake::moveBack ( Point  p,
Change change 
)
private

Checking if we need to remove the back of the snake from the labyrinth(we don't in case it has eaten the Ball)

Parameters
p- the desired position of movement
change- 2-dimensional array of changes needed to be applied to the labyrinth

Definition at line 233 of file snake.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Snake::moveHead ( Point  p,
Change change 
)
private

Moving snake head to a described by parameters position and updating the addition to the labyrinth.

Parameters
p- the new head position
change- 2-dimensional array of changes needed to be applied to the labyrinth

Definition at line 222 of file snake.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Snake::setDirection ( int  direction)

The method to set the direction where the snake is heading.

Parameters
direction- direction of the snake we are trying to set
Returns
- mark of successful set

Definition at line 294 of file snake.cpp.

Here is the caller graph for this function:

void Snake::setScheme ( )

Member Data Documentation

short Snake::direction
private

Definition at line 82 of file snake.h.

std::deque<Point> Snake::snakeBody
private

Definition at line 84 of file snake.h.

std::list<PointStyle> Snake::style
private

Definition at line 83 of file snake.h.


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