ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Committer:
shahidsajid
Date:
Wed May 08 12:13:28 2019 +0000
Revision:
31:eefa1d23a843
Parent:
30:43aace0fdbdf
Child:
32:1bc731f03a30
Documented and updated in-line comments for all the classes;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shahidsajid 10:6c6e09023942 1 #ifndef CRICKET_H
shahidsajid 10:6c6e09023942 2 #define CRICKET_H
shahidsajid 10:6c6e09023942 3
shahidsajid 10:6c6e09023942 4 #include "mbed.h"
shahidsajid 10:6c6e09023942 5 #include "N5110.h"
shahidsajid 10:6c6e09023942 6 #include "Gamepad.h"
shahidsajid 10:6c6e09023942 7 #include "Ball.h"
shahidsajid 14:122eaa3b7a50 8 #include "Scoreboard.h"
shahidsajid 21:a0904159e183 9 #include "UX.h"
shahidsajid 10:6c6e09023942 10
shahidsajid 10:6c6e09023942 11 /** Ball Class
shahidsajid 31:eefa1d23a843 12 @author Shahid Zubin Sajid el17szs
shahidsajid 31:eefa1d23a843 13 @brief Controls the bat in the Hero Cricket Game
shahidsajid 31:eefa1d23a843 14 @date May 2019
shahidsajid 31:eefa1d23a843 15
shahidsajid 10:6c6e09023942 16 */
shahidsajid 10:6c6e09023942 17 class Cricket
shahidsajid 10:6c6e09023942 18 {
shahidsajid 10:6c6e09023942 19
shahidsajid 10:6c6e09023942 20 public:
shahidsajid 30:43aace0fdbdf 21 /**
shahidsajid 30:43aace0fdbdf 22 @brief Constructor for the Cricket Object
shahidsajid 30:43aace0fdbdf 23 */
shahidsajid 10:6c6e09023942 24 Cricket();
shahidsajid 30:43aace0fdbdf 25 /**
shahidsajid 30:43aace0fdbdf 26 @brief Deconstructor for the Cricket Object
shahidsajid 30:43aace0fdbdf 27 */
shahidsajid 10:6c6e09023942 28 ~Cricket();
shahidsajid 30:43aace0fdbdf 29 /**
shahidsajid 28:d0b0a64a832d 30 * @brief Initlialises the Cricket class Object
shahidsajid 28:d0b0a64a832d 31 * @details Intialises the bat variables to the starting values
shahidsajid 28:d0b0a64a832d 32 * @details Initialises the other class objects used in the game
shahidsajid 28:d0b0a64a832d 33 */
shahidsajid 31:eefa1d23a843 34 void init(int ball_size, int bat_width,int bat_height);
shahidsajid 30:43aace0fdbdf 35 /**
shahidsajid 28:d0b0a64a832d 36 * @brief Draws the fielders, the outfield circle and the pitch onto the LCD
shahidsajid 30:43aace0fdbdf 37 * @param &lcd @details reference pointer for the LCD
shahidsajid 28:d0b0a64a832d 38 */
shahidsajid 10:6c6e09023942 39 void draw(N5110 &lcd);
shahidsajid 30:43aace0fdbdf 40 /**
shahidsajid 30:43aace0fdbdf 41 *@brief sets the positions for the 5 fielders in the game
shahidsajid 30:43aace0fdbdf 42 *@details randomly generates 5 fielders and sets the fielders co-ordinates and fielder number
shahidsajid 30:43aace0fdbdf 43 */
shahidsajid 10:6c6e09023942 44 void set_field(N5110 &lcd);
shahidsajid 30:43aace0fdbdf 45 /**
shahidsajid 28:d0b0a64a832d 46 * @brief Method to set the cor-dinates,direction and position for batsman to hit the ball
shahidsajid 28:d0b0a64a832d 47 * @param x @details Integer value for the x-cordinate
shahidsajid 28:d0b0a64a832d 48 * @param y @details Integer value for the y-cordinate
shahidsajid 28:d0b0a64a832d 49 * @param direction @details Direction variable to set the position direction
shahidsajid 28:d0b0a64a832d 50 * @param no @details integer to store the position number
shahidsajid 28:d0b0a64a832d 51 */
shahidsajid 13:924891519a95 52 void set_init_positions(int x,int y, Direction direction,int no);
shahidsajid 30:43aace0fdbdf 53 /**
shahidsajid 28:d0b0a64a832d 54 * @brief Sets the ball direction and sets _direction_set to 1
shahidsajid 28:d0b0a64a832d 55 * @details loops through the positions available and sets the direction to the arguement if found
shahidsajid 28:d0b0a64a832d 56 * @param dir @details Direction variable recieved as recived from the joystick during gameplay
shahidsajid 28:d0b0a64a832d 57 */
shahidsajid 30:43aace0fdbdf 58 void set_ball_direction(Direction dir);
shahidsajid 30:43aace0fdbdf 59 /**
shahidsajid 28:d0b0a64a832d 60 * @brief Draws the 5 outfield filders to the LCD
shahidsajid 28:d0b0a64a832d 61 * @details Loops through the fielders array and prints the fielders acc. to their cordinates
shahidsajid 28:d0b0a64a832d 62 * param &lcd @details reference pointer for the LCD
shahidsajid 28:d0b0a64a832d 63 */
shahidsajid 10:6c6e09023942 64 void draw_field(N5110 &lcd);
shahidsajid 30:43aace0fdbdf 65 /**
shahidsajid 28:d0b0a64a832d 66 * @brief Method to set the cor-dinates,direction and position for batsman to hit the ball
shahidsajid 28:d0b0a64a832d 67 * @param x @details Integer value for the x-cordinate
shahidsajid 28:d0b0a64a832d 68 * @param y @details Integer value for the y-cordinate
shahidsajid 28:d0b0a64a832d 69 * @param direction @details Direction variable to set the position direction
shahidsajid 28:d0b0a64a832d 70 * @param no @details integer to store the position number
shahidsajid 28:d0b0a64a832d 71 */
shahidsajid 19:e1ded5acb64a 72 void update_game(int checkHit,int loft_check, Direction dir,Gamepad &pad,N5110 &lcd);
shahidsajid 30:43aace0fdbdf 73 /**
shahidsajid 30:43aace0fdbdf 74 * @brief Method checks if ball is hit, if ball is lofted and gets the ball direction
shahidsajid 30:43aace0fdbdf 75 * @param &lcd @details reference pointer for the LCD
shahidsajid 30:43aace0fdbdf 76 * @param &pad @details Takes a reference pointer to a Gamepad object
shahidsajid 30:43aace0fdbdf 77 */
shahidsajid 11:f481ec642cc5 78 void play_game(N5110 &lcd,Gamepad &pad);
shahidsajid 30:43aace0fdbdf 79 /**
shahidsajid 28:d0b0a64a832d 80 * @brief Updates the score by adding runs scored during the round to score
shahidsajid 28:d0b0a64a832d 81 * @param checkUpdate @details integer value which validates that the game has been updated
shahidsajid 28:d0b0a64a832d 82 * @param runs @details Integer value which stores the runs scored during the round
shahidsajid 28:d0b0a64a832d 83 * @param &pad @details Takes a reference pointer to a Gamepad object
shahidsajid 28:d0b0a64a832d 84 */
shahidsajid 31:eefa1d23a843 85 void update_scoreboard(int check_update, int runs,Gamepad &pad);
shahidsajid 28:d0b0a64a832d 86 /**
shahidsajid 28:d0b0a64a832d 87 * @brief method when a batsman is out, screen updates and game resets.
shahidsajid 28:d0b0a64a832d 88 * @param option @details integer value which identifies the way batsman is out
shahidsajid 28:d0b0a64a832d 89 * @param &pad @details Takes a reference pointer to a Gamepad object
shahidsajid 30:43aace0fdbdf 90 * @param &lcd @details Reference pointer for the LCD
shahidsajid 28:d0b0a64a832d 91 */
shahidsajid 19:e1ded5acb64a 92 void batsman_out(int option,Gamepad &pad, N5110 &lcd);
shahidsajid 30:43aace0fdbdf 93 /**
shahidsajid 28:d0b0a64a832d 94 * @brief method which compares score and target, if true game is won and game resets
shahidsajid 30:43aace0fdbdf 95 * @param &lcd @details Reference pointer for the LCD
shahidsajid 28:d0b0a64a832d 96 */
shahidsajid 18:a260ce8db9e7 97 void check_victory(N5110 &lcd);
shahidsajid 30:43aace0fdbdf 98 /**
shahidsajid 29:f7a2d2a755ec 99 * @brief Method called after each round, checks if it is a new round or new game
shahidsajid 29:f7a2d2a755ec 100 * @param runs @details Integer value which stores the runs scored during the round
shahidsajid 29:f7a2d2a755ec 101 * @param &pad @details Takes a reference pointer to a Gamepad object
shahidsajid 29:f7a2d2a755ec 102 */
shahidsajid 19:e1ded5acb64a 103 void game(N5110 &lcd,Gamepad &pad);
shahidsajid 30:43aace0fdbdf 104 /**
shahidsajid 29:f7a2d2a755ec 105 * @brief Prints the introduction screen when the game is first loaded up
shahidsajid 29:f7a2d2a755ec 106 * @param &lcd @details reference pointer for the LCD
shahidsajid 29:f7a2d2a755ec 107 */
shahidsajid 24:23fd6b451db7 108 void intro(N5110 &lcd);
shahidsajid 30:43aace0fdbdf 109 /**
shahidsajid 29:f7a2d2a755ec 110 * @brief Method which checks if the game is won, lost and updates the game status
shahidsajid 29:f7a2d2a755ec 111 * @param &lcd @details reference pointer for the LCD
shahidsajid 29:f7a2d2a755ec 112 */
shahidsajid 24:23fd6b451db7 113 bool game_status(N5110 &lcd);
shahidsajid 30:43aace0fdbdf 114 /**
shahidsajid 29:f7a2d2a755ec 115 * @brief Sets the positions for where the ball can be hit
shahidsajid 30:43aace0fdbdf 116 * @details stores the positions in a position array
shahidsajid 30:43aace0fdbdf 117 */
shahidsajid 12:954da4f4e565 118 void init_positions();
shahidsajid 30:43aace0fdbdf 119 /**
shahidsajid 30:43aace0fdbdf 120 * @brief Resets the game variables for each round
shahidsajid 30:43aace0fdbdf 121 */
shahidsajid 19:e1ded5acb64a 122 void round_reset();
shahidsajid 29:f7a2d2a755ec 123 /**
shahidsajid 29:f7a2d2a755ec 124 * @brief Resets the variables for the start of each game
shahidsajid 30:43aace0fdbdf 125 */
shahidsajid 19:e1ded5acb64a 126 void game_reset();
shahidsajid 30:43aace0fdbdf 127 /**
shahidsajid 29:f7a2d2a755ec 128 * @brief Method which checks if a fielder is present in the direciton of ball hit
shahidsajid 30:43aace0fdbdf 129 * @param dir @details Direction variable which stores the direction of the ball
shahidsajid 29:f7a2d2a755ec 130 * @returns an integer value fielder no if a fielder is present, -1 if no fielder
shahidsajid 30:43aace0fdbdf 131 */
shahidsajid 13:924891519a95 132 int check_fielder(Direction dir);
shahidsajid 30:43aace0fdbdf 133 /**
shahidsajid 29:f7a2d2a755ec 134 * @brief Method which checks if a fielder is present in the direciton of ball hit
shahidsajid 29:f7a2d2a755ec 135 * @returns a boolean value,true if ball count is equal to ball limit and false if it's < ball limit
shahidsajid 30:43aace0fdbdf 136 */
shahidsajid 19:e1ded5acb64a 137 bool check_ball_count(N5110 &lcd);
shahidsajid 10:6c6e09023942 138 private:
shahidsajid 29:f7a2d2a755ec 139 //Ball object variable
shahidsajid 30:43aace0fdbdf 140 Ball _ball;
shahidsajid 29:f7a2d2a755ec 141 //Bat object variable
shahidsajid 30:43aace0fdbdf 142 Bat _bat;
shahidsajid 29:f7a2d2a755ec 143 //Scoreboard object variable
shahidsajid 30:43aace0fdbdf 144 Scoreboard _scoreboard;
shahidsajid 29:f7a2d2a755ec 145 //UX object variable
shahidsajid 30:43aace0fdbdf 146 UX _ux;
shahidsajid 30:43aace0fdbdf 147 //Fielder Positions struct which holds the x & y cordinates and fielder no.
shahidsajid 12:954da4f4e565 148 struct fielder_positions{
shahidsajid 12:954da4f4e565 149 Direction dir;
shahidsajid 12:954da4f4e565 150 int x;
shahidsajid 12:954da4f4e565 151 int y;
shahidsajid 12:954da4f4e565 152 int no;
shahidsajid 12:954da4f4e565 153 };
shahidsajid 30:43aace0fdbdf 154
shahidsajid 29:f7a2d2a755ec 155 //Array which stores the positions for the ball to be hit
shahidsajid 12:954da4f4e565 156 fielder_positions positions[7];
shahidsajid 30:43aace0fdbdf 157
shahidsajid 29:f7a2d2a755ec 158 /*Struct created for fielders that are in the outfield
shahidsajid 30:43aace0fdbdf 159 stores the fielder cordinates on the LCD and the position no.
shahidsajid 29:f7a2d2a755ec 160 */
shahidsajid 10:6c6e09023942 161 struct Fielder{
shahidsajid 10:6c6e09023942 162 Direction dir;
shahidsajid 10:6c6e09023942 163 int x;
shahidsajid 10:6c6e09023942 164 int y;
shahidsajid 10:6c6e09023942 165 int position;
shahidsajid 10:6c6e09023942 166 };
shahidsajid 30:43aace0fdbdf 167 //Fielder array that stores the no. of fielders and it's characteristics
shahidsajid 10:6c6e09023942 168 Fielder field[5];
shahidsajid 30:43aace0fdbdf 169 //integer variable that checks if direction of ball has been set during gameplay
shahidsajid 30:43aace0fdbdf 170 int direction_set;
shahidsajid 30:43aace0fdbdf 171 Vector2D ball_position;
shahidsajid 30:43aace0fdbdf 172 //Direction object to store the ball direction
shahidsajid 30:43aace0fdbdf 173 Direction ball_direction;
shahidsajid 30:43aace0fdbdf 174 /*integer variable which checks if the ball has been bowled
shahidsajid 30:43aace0fdbdf 175 it is used as a flag */
shahidsajid 26:6427f09cf8d3 176 int _check_bowled;
shahidsajid 29:f7a2d2a755ec 177 //Integer variable sued as counter positions initialised in the field
shahidsajid 26:6427f09cf8d3 178 int _init_field_counter;
shahidsajid 29:f7a2d2a755ec 179 // Integer value used as a counter for the no. of fielders
shahidsajid 26:6427f09cf8d3 180 int _fielders_count;
shahidsajid 29:f7a2d2a755ec 181 //Integer variable used as a flag to indicate start of new round
shahidsajid 26:6427f09cf8d3 182 int _new_round;
shahidsajid 29:f7a2d2a755ec 183 //Integer array to store no. of fielders during set_field()
shahidsajid 30:43aace0fdbdf 184 int fieldNumbers[10];
shahidsajid 30:43aace0fdbdf 185 /*Integer variable used as an array index for the position in the outfield where
shahidsajid 29:f7a2d2a755ec 186 the ball has been hit*/
shahidsajid 20:9d21599fe350 187 int _position_no;
shahidsajid 30:43aace0fdbdf 188 //Integer variable that stores no. of balls that are to be played during each game
shahidsajid 26:6427f09cf8d3 189 int _ball_limit;
shahidsajid 29:f7a2d2a755ec 190 //Integer variable used as a flag to indicate start of new game
shahidsajid 26:6427f09cf8d3 191 int _new_game;
shahidsajid 30:43aace0fdbdf 192 //Integer variable used as a flag to indicate that ball has reached destination fielder
shahidsajid 26:6427f09cf8d3 193 int _check_update;
shahidsajid 29:f7a2d2a755ec 194 //Integer variable used to check if the ball has been hit
shahidsajid 26:6427f09cf8d3 195 int _check_hit;
shahidsajid 29:f7a2d2a755ec 196 //Integer variable used as a flag to indicate that ball has been hit
shahidsajid 26:6427f09cf8d3 197 int _set_hit;
shahidsajid 29:f7a2d2a755ec 198 //Integer variable used as a flag to indicate that the hit is lofted
shahidsajid 26:6427f09cf8d3 199 int _set_loft;
shahidsajid 30:43aace0fdbdf 200 //Integer variable used to check if the hit is lofted
shahidsajid 30:43aace0fdbdf 201 int _loft_check;
shahidsajid 10:6c6e09023942 202 };
shahidsajid 10:6c6e09023942 203 #endif