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/Cricket.h
- Committer:
- shahidsajid
- Date:
- 2019-05-08
- Revision:
- 33:9d34ef219fff
- Parent:
- 32:1bc731f03a30
- Child:
- 34:d9099874bbc3
File content as of revision 33:9d34ef219fff:
#ifndef CRICKET_H #define CRICKET_H #include "mbed.h" #include "N5110.h" #include "Gamepad.h" #include "Ball.h" #include "Scoreboard.h" #include "UX.h" /** Cricket Class * @author Shahid Zubin Sajid el17szs * @brief Controls the bat in the Hero Cricket Game * @date May 2019 */ class Cricket { public: /** Constructor */ Cricket(); /** Deconstructor */ ~Cricket(); /** * @brief Initlialises the Cricket class Object * @details Intialises the bat variables to the starting values * @details Initialises the other class objects used in the game */ void init(int ball_size, int bat_width,int bat_height); /** * @brief Draws the fielders, the outfield circle and the pitch onto the LCD * @param &lcd @details reference pointer for the LCD */ void draw(N5110 &lcd); /** *@brief sets the positions for the 5 fielders in the game *@details randomly generates 5 fielders and sets the fielders co-ordinates and fielder number */ void set_field(N5110 &lcd); /** * @brief Method to set the cor-dinates,direction and position for batsman to hit the ball * @param x @details Integer value for the x-cordinate * @param y @details Integer value for the y-cordinate * @param direction @details Direction variable to set the position direction * @param no @details integer to store the position number */ void set_init_positions(int x,int y, Direction direction,int no); /** * @brief Sets the ball direction and sets _direction_set to 1 * @details loops through the positions available and sets the direction to the arguement if found * @param dir @details Direction variable recieved as recived from the joystick during gameplay */ void set_ball_direction(Direction dir); /** * @brief Draws the 5 outfield filders to the LCD * @details Loops through the fielders array and prints the fielders acc. to their cordinates * param &lcd @details reference pointer for the LCD */ void draw_field(N5110 &lcd); /** * @brief Method to set the cor-dinates,direction and position for batsman to hit the ball * @param x @details Integer value for the x-cordinate * @param y @details Integer value for the y-cordinate * @param direction @details Direction variable to set the position direction * @param no @details integer to store the position number */ void update_game(int checkHit,int loft_check, Direction dir,Gamepad &pad,N5110 &lcd); /** * @brief Method checks if ball is hit, if ball is lofted and gets the ball direction * @param &lcd @details reference pointer for the LCD * @param &pad @details Takes a reference pointer to a Gamepad object */ void play_game(N5110 &lcd,Gamepad &pad); /** * @brief Updates the score by adding runs scored during the round to score * @param checkUpdate @details integer value which validates that the game has been updated * @param runs @details Integer value which stores the runs scored during the round * @param &pad @details Takes a reference pointer to a Gamepad object */ void update_scoreboard(int check_update, int runs,Gamepad &pad); /** * @brief method when a batsman is out, screen updates and game resets. * @param option @details integer value which identifies the way batsman is out * @param &pad @details Takes a reference pointer to a Gamepad object * @param &lcd @details Reference pointer for the LCD */ void batsman_out(int option,Gamepad &pad, N5110 &lcd); /** * @brief method which compares score and target, if true game is won and game resets * @param &lcd @details Reference pointer for the LCD */ void check_victory(N5110 &lcd); /** * @brief Method called after each round, checks if it is a new round or new game * @param runs @details Integer value which stores the runs scored during the round * @param &pad @details Takes a reference pointer to a Gamepad object */ void game(N5110 &lcd,Gamepad &pad); /** * @brief Prints the introduction screen when the game is first loaded up * @param &lcd @details reference pointer for the LCD */ void intro(N5110 &lcd); /** * @brief Method which checks if the game is won, lost and updates the game status * @param &lcd @details reference pointer for the LCD */ bool game_status(N5110 &lcd); /** * @brief Sets the positions for where the ball can be hit * @details stores the positions in a position array */ void init_positions(); /** * @brief Resets the game variables for each round */ void round_reset(); /** * @brief Resets the variables for the start of each game */ void game_reset(); /** * @brief Method which checks if a fielder is present in the direciton of ball hit * @param dir @details Direction variable which stores the direction of the ball * @returns an integer value fielder no if a fielder is present, -1 if no fielder */ int check_fielder(Direction dir); /** * @brief 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 */ bool check_ball_count(N5110 &lcd); private: //Ball object variable Ball _ball; //Bat object variable Bat _bat; //Scoreboard object variable Scoreboard _scoreboard; //UX object variable UX _ux; //Fielder Positions struct which holds the x & y cordinates and fielder no. struct fielder_positions{ Direction dir; int x; int y; int no; }; //Array which stores the positions for the ball to be hit fielder_positions positions[7]; /*Struct created for fielders that are in the outfield stores the fielder cordinates on the LCD and the position no. */ struct Fielder{ Direction dir; int x; int y; int position; }; /**Fielder array that stores the no. of fielders and it's characteristics*/ Fielder field[5]; /**integer variable that checks if direction of ball has been set during gameplay*/ int direction_set; Vector2D ball_position; /**Direction object to store the ball direction*/ Direction ball_direction; /**integer variable which checks if the ball has been bowled it is used as a flag */ int _check_bowled; /**Integer variable sued as counter positions initialised in the field**/ int _init_field_counter; /**Integer value used as a counter for the no. of fielders*/ int _fielders_count; /**Integer variable used as a flag to indicate start of new round*/ int _new_round; /**Integer array to store no. of fielders during set_field()*/ int fieldNumbers[10]; /**Integer variable used as an array index for the position in the outfield where the ball has been hit*/ int _position_no; /**Integer variable that stores no. of balls that are to be played during each game*/ int _ball_limit; //Integer variable used as a flag to indicate start of new game int _new_game; /**Integer variable used as a flag to indicate that ball has reached destination fielder*/ int _check_update; /**Integer variable used to check if the ball has been hit*/ int _check_hit; /**Integer variable used as a flag to indicate that ball has been hit*/ int _set_hit; /**Integer variable used as a flag to indicate that the hit is lofted*/ int _set_loft; /**Integer variable used to check if the hit is lofted*/ int _loft_check; }; #endif