Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Cricket Class Reference
#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.
- 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
method when a batsman is out, screen updates and game resets.
- Parameters:
-
option integer value which identifies the way batsman is out &pad Takes a reference pointer to a Gamepad object &lcd Reference 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:
-
dir Direction 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:
-
&lcd Reference 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:
-
&lcd reference 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.
Method called after each round, checks if it is a new round or new game.
- Parameters:
-
runs Integer value which stores the runs scored during the round &pad Takes 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:
-
&lcd reference 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:
-
&lcd reference pointer for the LCD
Definition at line 70 of file Cricket.cpp.
Method checks if ball is hit, if ball is lofted and gets the ball direction.
- Parameters:
-
&lcd reference pointer for the LCD &pad Takes 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:
-
dir Direction 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:
-
x Integer value for the x-cordinate y Integer value for the y-cordinate direction Direction variable to set the position direction no integer to store the position number
Definition at line 155 of file Cricket.cpp.
Method to set the cor-dinates,direction and position for batsman to hit the ball.
- Parameters:
-
x Integer value for the x-cordinate y Integer value for the y-cordinate direction Direction variable to set the position direction no integer 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:
-
checkUpdate integer value which validates that the game has been updated runs Integer value which stores the runs scored during the round &pad Takes a reference pointer to a Gamepad object
Definition at line 218 of file Cricket.cpp.
Generated on Tue Jul 19 2022 18:37:30 by
1.7.2