ELEC2645 (2017/18) / Mbed 2 deprecated ll13jrm

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Snake Class Reference

Snake Class Reference

Snake Class. More...

#include <Snake.h>

Public Member Functions

void init (Direction in, Direction cur, int pos_x, int pos_y)
 Initialises the snakes direction and position when game starts.
void update (Direction in, Direction cur)
 Updates methods for snake head.
void draw (N5110 &lcd)
 Draws snake head on lcd.
void set_snake_direction (Direction input, Direction current)
 Gives the next direction of the snake.
void set_centre (Direction input, Direction current)
 Determines the possible next directions for the current direction CENTRE.
void set_north (Direction input, Direction current)
 Determines the possible next directions for the current direction North.
void set_east (Direction input, Direction current)
 Determines the possible next directions for the current direction East.
void set_south (Direction input, Direction current)
 Determines the possible next directions for the current direction South.
void set_west (Direction input, Direction current)
 Determines the possible next directions for the current direction West.
Direction get_snake_direction ()
 Gets snake direction.
void set_current_direction (Direction input)
 Sets the current direction such that it is never CENTRE.
Direction get_current_direction ()
 Gets current direction.
void set_snake_position (Direction next)
 Given the next direction increments the snake's position appropriatley.
Vector2D get_snake_position ()
 Gets updated position.

Detailed Description

Snake Class.

Describes the methods and functions for the snake head

Author:
Joshua R. Marshall
Date:
Feb, 2018

Definition at line 14 of file Snake.h.


Member Function Documentation

void draw ( N5110 lcd )

Draws snake head on lcd.

Definition at line 36 of file Snake.cpp.

Direction get_current_direction (  )

Gets current direction.

Returns:
returns current direction

Definition at line 351 of file Snake.cpp.

Direction get_snake_direction (  )

Gets snake direction.

Returns:
returns next direction of the snake head

Definition at line 91 of file Snake.cpp.

Vector2D get_snake_position (  )

Gets updated position.

Returns:
returns new position

Definition at line 413 of file Snake.cpp.

void init ( Direction  in,
Direction  cur,
int  pos_x,
int  pos_y 
)

Initialises the snakes direction and position when game starts.

Parameters:
Inputdirection from pad
Currentdirection of snake
pos_xx position
pos_yy position

Definition at line 17 of file Snake.cpp.

void set_centre ( Direction  input,
Direction  current 
)

Determines the possible next directions for the current direction CENTRE.

can be any direction except Centre

Parameters:
Inputdirection from pad
Currentdirection of snake

Definition at line 100 of file Snake.cpp.

void set_current_direction ( Direction  input )

Sets the current direction such that it is never CENTRE.

Parameters:
Inputdirection from pad

Definition at line 329 of file Snake.cpp.

void set_east ( Direction  input,
Direction  current 
)

Determines the possible next directions for the current direction East.

Cannot be West

Parameters:
Inputdirection from pad
Currentdirection of snake

Definition at line 189 of file Snake.cpp.

void set_north ( Direction  input,
Direction  current 
)

Determines the possible next directions for the current direction North.

Cannot be South

Parameters:
Inputdirection from pad
Currentdirection of snake

Definition at line 145 of file Snake.cpp.

void set_snake_direction ( Direction  input,
Direction  current 
)

Gives the next direction of the snake.

Gives the next direction given the current and input directions

Parameters:
Inputdirection from pad
Currentdirection of snake

Definition at line 43 of file Snake.cpp.

void set_snake_position ( Direction  next )

Given the next direction increments the snake's position appropriatley.

Parameters:
Nextdirection from get_direction

Definition at line 360 of file Snake.cpp.

void set_south ( Direction  input,
Direction  current 
)

Determines the possible next directions for the current direction South.

Cannot be North

Parameters:
Inputdirection from pad
Currentdirection of snake

Definition at line 236 of file Snake.cpp.

void set_west ( Direction  input,
Direction  current 
)

Determines the possible next directions for the current direction West.

Cannot be East

Parameters:
Inputdirection from pad
Currentdirection of snake

Definition at line 282 of file Snake.cpp.

void update ( Direction  in,
Direction  cur 
)

Updates methods for snake head.

Parameters:
Inputdirection from pad
Currentdirection of snake

Definition at line 26 of file Snake.cpp.