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.h
00001 #ifndef CRICKET_H 00002 #define CRICKET_H 00003 00004 #include "mbed.h" 00005 #include "N5110.h" 00006 #include "Gamepad.h" 00007 #include "Ball.h" 00008 #include "Scoreboard.h" 00009 #include "UX.h" 00010 00011 /** Cricket Class 00012 * @author Shahid Zubin Sajid el17szs 00013 * @brief Main Game Engine for the Hero Cricket Game 00014 * @date May 2019 00015 */ 00016 class Cricket 00017 { 00018 00019 public: 00020 /** Constructor */ 00021 Cricket(); 00022 /** Deconstructor */ 00023 ~Cricket(); 00024 /** 00025 * @brief Initlialises the Cricket class Object 00026 * @details Intialises the bat variables to the starting values 00027 * @details Initialises the other class objects used in the game 00028 */ 00029 void init(int ball_size, int bat_width,int bat_height); 00030 /** 00031 * @brief Draws the fielders, the outfield circle and the pitch onto the LCD 00032 * @param &lcd @details reference pointer for the LCD 00033 */ 00034 void draw(N5110 &lcd); 00035 /** 00036 *@brief sets the positions for the 5 fielders in the game 00037 *@details randomly generates 5 fielders and sets the fielders co-ordinates and fielder number 00038 */ 00039 void set_field(N5110 &lcd); 00040 /** 00041 * @brief Method to set the cor-dinates,direction and position for batsman to hit the ball 00042 * @param x @details Integer value for the x-cordinate 00043 * @param y @details Integer value for the y-cordinate 00044 * @param direction @details Direction variable to set the position direction 00045 * @param no @details integer to store the position number 00046 */ 00047 void set_init_positions(int x,int y, Direction direction,int no); 00048 /** 00049 * @brief Sets the ball direction and sets _direction_set to 1 00050 * @details loops through the positions available and sets the direction to the arguement if found 00051 * @param dir @details Direction variable recieved as recived from the joystick during gameplay 00052 */ 00053 void set_ball_direction(Direction dir); 00054 /** 00055 * @brief Draws the 5 outfield filders to the LCD 00056 * @details Loops through the fielders array and prints the fielders acc. to their cordinates 00057 * param &lcd @details reference pointer for the LCD 00058 */ 00059 void draw_field(N5110 &lcd); 00060 /** 00061 * @brief Method to set the cor-dinates,direction and position for batsman to hit the ball 00062 * @param x @details Integer value for the x-cordinate 00063 * @param y @details Integer value for the y-cordinate 00064 * @param direction @details Direction variable to set the position direction 00065 * @param no @details integer to store the position number 00066 */ 00067 void update_game(int checkHit,int loft_check, Direction dir,Gamepad &pad,N5110 &lcd); 00068 /** 00069 * @brief Method checks if ball is hit, if ball is lofted and gets the ball direction 00070 * @param &lcd @details reference pointer for the LCD 00071 * @param &pad @details Takes a reference pointer to a Gamepad object 00072 */ 00073 void play_game(N5110 &lcd,Gamepad &pad); 00074 /** 00075 * @brief Updates the score by adding runs scored during the round to score 00076 * @param checkUpdate @details integer value which validates that the game has been updated 00077 * @param runs @details Integer value which stores the runs scored during the round 00078 * @param &pad @details Takes a reference pointer to a Gamepad object 00079 */ 00080 void update_scoreboard(int check_update, int runs,Gamepad &pad); 00081 /** 00082 * @brief method when a batsman is out, screen updates and game resets. 00083 * @param option @details integer value which identifies the way batsman is out 00084 * @param &pad @details Takes a reference pointer to a Gamepad object 00085 * @param &lcd @details Reference pointer for the LCD 00086 */ 00087 void batsman_out(int option,Gamepad &pad, N5110 &lcd); 00088 /** 00089 * @brief method which compares score and target, if true game is won and game resets 00090 * @param &lcd @details Reference pointer for the LCD 00091 */ 00092 void check_victory(N5110 &lcd); 00093 /** 00094 * @brief Method called after each round, checks if it is a new round or new game 00095 * @param runs @details Integer value which stores the runs scored during the round 00096 * @param &pad @details Takes a reference pointer to a Gamepad object 00097 */ 00098 void game(N5110 &lcd,Gamepad &pad); 00099 /** 00100 * @brief Prints the introduction screen when the game is first loaded up 00101 * @param &lcd @details reference pointer for the LCD 00102 */ 00103 void intro(N5110 &lcd); 00104 /** 00105 * @brief Method which checks if the game is won, lost and updates the game status 00106 * @param &lcd @details reference pointer for the LCD 00107 */ 00108 bool game_status(N5110 &lcd); 00109 /** 00110 * @brief Sets the positions for where the ball can be hit 00111 * @details stores the positions in a position array 00112 */ 00113 void init_positions(); 00114 /** 00115 * @brief Resets the game variables for each round 00116 */ 00117 void round_reset(); 00118 /** 00119 * @brief Resets the variables for the start of each game 00120 */ 00121 void game_reset(); 00122 /** 00123 * @brief Method which checks if a fielder is present in the direciton of ball hit 00124 * @param dir @details Direction variable which stores the direction of the ball 00125 * @returns an integer value fielder no if a fielder is present, -1 if no fielder 00126 */ 00127 int check_fielder(Direction dir); 00128 /** 00129 * @brief Method which checks if a fielder is present in the direciton of ball hit 00130 * @returns a boolean value,true if ball count is equal to ball limit and false if it's < ball limit 00131 */ 00132 bool check_ball_count(N5110 &lcd); 00133 private: 00134 //Ball object variable 00135 Ball _ball; 00136 //Bat object variable 00137 Bat _bat; 00138 //Scoreboard object variable 00139 Scoreboard _scoreboard; 00140 //UX object variable 00141 UX _ux; 00142 //Fielder Positions struct which holds the x & y cordinates and fielder no. 00143 struct fielder_positions{ 00144 Direction dir; 00145 int x; 00146 int y; 00147 int no; 00148 }; 00149 00150 //Array which stores the positions for the ball to be hit 00151 fielder_positions positions[7]; 00152 00153 /*Struct created for fielders that are in the outfield 00154 stores the fielder cordinates on the LCD and the position no. 00155 */ 00156 struct Fielder{ 00157 Direction dir; 00158 int x; 00159 int y; 00160 int position; 00161 }; 00162 /**Fielder array that stores the no. of fielders and it's characteristics*/ 00163 Fielder field[5]; 00164 /**integer variable that checks if direction of ball has been set during gameplay*/ 00165 int direction_set; 00166 Vector2D ball_position; 00167 /**Direction object to store the ball direction*/ 00168 Direction ball_direction; 00169 /**integer variable which checks if the ball has been bowled 00170 it is used as a flag */ 00171 int _check_bowled; 00172 /**Integer variable sued as counter positions initialised in the field**/ 00173 int _init_field_counter; 00174 /**Integer value used as a counter for the no. of fielders*/ 00175 int _fielders_count; 00176 /**Integer variable used as a flag to indicate start of new round*/ 00177 int _new_round; 00178 /**Integer array to store no. of fielders during set_field()*/ 00179 int fieldNumbers[10]; 00180 /**Integer variable used as an array index for the position in the outfield where 00181 the ball has been hit*/ 00182 int _position_no; 00183 /**Integer variable that stores no. of balls that are to be played during each game*/ 00184 int _ball_limit; 00185 //Integer variable used as a flag to indicate start of new game 00186 int _new_game; 00187 /**Integer variable used as a flag to indicate that ball has reached destination fielder*/ 00188 int _check_update; 00189 /**Integer variable used to check if the ball has been hit*/ 00190 int _check_hit; 00191 /**Integer variable used as a flag to indicate that ball has been hit*/ 00192 int _set_hit; 00193 /**Integer variable used as a flag to indicate that the hit is lofted*/ 00194 int _set_loft; 00195 /**Integer variable used to check if the hit is lofted*/ 00196 int _loft_check; 00197 }; 00198 #endif
Generated on Tue Jul 19 2022 18:37:30 by
1.7.2