ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Cricket Class Reference

Cricket Class Reference

Cricket Class. More...

#include <Cricket.h>

Public Member Functions

 Cricket ()
 Constructor.
 ~Cricket ()
 Deconstructor.
void init (int ball_size, int bat_width, int bat_height)
 Initlialises the Cricket class Object.
void draw (N5110 &lcd)
 Draws the fielders, the outfield circle and the pitch onto the LCD.
void set_field (N5110 &lcd)
 sets the positions for the 5 fielders in the game
void set_init_positions (int x, int y, Direction direction, int no)
 Method to set the cor-dinates,direction and position for batsman to hit the ball.
void set_ball_direction (Direction dir)
 Sets the ball direction and sets _direction_set to 1.
void draw_field (N5110 &lcd)
 Draws the 5 outfield filders to the LCD.
void update_game (int checkHit, int loft_check, Direction dir, Gamepad &pad, N5110 &lcd)
 Method to set the cor-dinates,direction and position for batsman to hit the ball.
void play_game (N5110 &lcd, Gamepad &pad)
 Method checks if ball is hit, if ball is lofted and gets the ball direction.
void update_scoreboard (int check_update, int runs, Gamepad &pad)
 Updates the score by adding runs scored during the round to score.
void batsman_out (int option, Gamepad &pad, N5110 &lcd)
 method when a batsman is out, screen updates and game resets.
void check_victory (N5110 &lcd)
 method which compares score and target, if true game is won and game resets
void game (N5110 &lcd, Gamepad &pad)
 Method called after each round, checks if it is a new round or new game.
void intro (N5110 &lcd)
 Prints the introduction screen when the game is first loaded up.
bool game_status (N5110 &lcd)
 Method which checks if the game is won, lost and updates the game status.
void init_positions ()
 Sets the positions for where the ball can be hit.
void round_reset ()
 Resets the game variables for each round.
void game_reset ()
 Resets the variables for the start of each game.
int check_fielder (Direction dir)
 Method which checks if a fielder is present in the direciton of ball hit.
bool check_ball_count (N5110 &lcd)
 Method which checks if a fielder is present in the direciton of ball hit.

Detailed Description

Cricket Class.

Author:
Shahid Zubin Sajid el17szs Main Game Engine for the Hero Cricket Game
Date:
May 2019

Definition at line 16 of file Cricket.h.


Constructor & Destructor Documentation

Cricket (  )

Constructor.

Definition at line 6 of file Cricket.cpp.

~Cricket (  )

Deconstructor.

Definition at line 11 of file Cricket.cpp.


Member Function Documentation

void batsman_out ( int  option,
Gamepad pad,
N5110 lcd 
)

method when a batsman is out, screen updates and game resets.

Parameters:
optioninteger value which identifies the way batsman is out
&padTakes a reference pointer to a Gamepad object
&lcdReference pointer for the LCD

Definition at line 242 of file Cricket.cpp.

bool check_ball_count ( N5110 lcd )

Method which checks if a fielder is present in the direciton of ball hit.

Returns:
a boolean value,true if ball count is equal to ball limit and false if it's < ball limit

Definition at line 119 of file Cricket.cpp.

int check_fielder ( Direction  dir )

Method which checks if a fielder is present in the direciton of ball hit.

Parameters:
dirDirection variable which stores the direction of the ball
Returns:
an integer value fielder no if a fielder is present, -1 if no fielder

Definition at line 278 of file Cricket.cpp.

void check_victory ( N5110 lcd )

method which compares score and target, if true game is won and game resets

Parameters:
&lcdReference pointer for the LCD

Definition at line 133 of file Cricket.cpp.

void draw ( N5110 lcd )

Draws the fielders, the outfield circle and the pitch onto the LCD.

Parameters:
&lcdreference pointer for the LCD

Definition at line 254 of file Cricket.cpp.

void draw_field ( N5110 lcd )

Draws the 5 outfield filders to the LCD.

Loops through the fielders array and prints the fielders acc. to their cordinates param &lcd

reference pointer for the LCD

Definition at line 292 of file Cricket.cpp.

void game ( N5110 lcd,
Gamepad pad 
)

Method called after each round, checks if it is a new round or new game.

Parameters:
runsInteger value which stores the runs scored during the round
&padTakes a reference pointer to a Gamepad object

Definition at line 75 of file Cricket.cpp.

void game_reset (  )

Resets the variables for the start of each game.

Definition at line 59 of file Cricket.cpp.

bool game_status ( N5110 lcd )

Method which checks if the game is won, lost and updates the game status.

Parameters:
&lcdreference pointer for the LCD

Definition at line 100 of file Cricket.cpp.

void init ( int  ball_size,
int  bat_width,
int  bat_height 
)

Initlialises the Cricket class Object.

Intialises the bat variables to the starting values

Initialises the other class objects used in the game

Definition at line 19 of file Cricket.cpp.

void init_positions (  )

Sets the positions for where the ball can be hit.

stores the positions in a position array

Definition at line 145 of file Cricket.cpp.

void intro ( N5110 lcd )

Prints the introduction screen when the game is first loaded up.

Parameters:
&lcdreference pointer for the LCD

Definition at line 70 of file Cricket.cpp.

void play_game ( N5110 lcd,
Gamepad pad 
)

Method checks if ball is hit, if ball is lofted and gets the ball direction.

Parameters:
&lcdreference pointer for the LCD
&padTakes a reference pointer to a Gamepad object

Definition at line 163 of file Cricket.cpp.

void round_reset (  )

Resets the game variables for each round.

Definition at line 42 of file Cricket.cpp.

void set_ball_direction ( Direction  dir )

Sets the ball direction and sets _direction_set to 1.

loops through the positions available and sets the direction to the arguement if found

Parameters:
dirDirection variable recieved as recived from the joystick during gameplay

Definition at line 264 of file Cricket.cpp.

void set_field ( N5110 lcd )

sets the positions for the 5 fielders in the game

randomly generates 5 fielders and sets the fielders co-ordinates and fielder number

Definition at line 302 of file Cricket.cpp.

void set_init_positions ( int  x,
int  y,
Direction  direction,
int  no 
)

Method to set the cor-dinates,direction and position for batsman to hit the ball.

Parameters:
xInteger value for the x-cordinate
yInteger value for the y-cordinate
directionDirection variable to set the position direction
nointeger to store the position number

Definition at line 155 of file Cricket.cpp.

void update_game ( int  checkHit,
int  loft_check,
Direction  dir,
Gamepad pad,
N5110 lcd 
)

Method to set the cor-dinates,direction and position for batsman to hit the ball.

Parameters:
xInteger value for the x-cordinate
yInteger value for the y-cordinate
directionDirection variable to set the position direction
nointeger to store the position number

Definition at line 180 of file Cricket.cpp.

void update_scoreboard ( int  check_update,
int  runs,
Gamepad pad 
)

Updates the score by adding runs scored during the round to score.

Parameters:
checkUpdateinteger value which validates that the game has been updated
runsInteger value which stores the runs scored during the round
&padTakes a reference pointer to a Gamepad object

Definition at line 218 of file Cricket.cpp.