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@28:d0b0a64a832d, 2019-05-07 (annotated)
- Committer:
- shahidsajid
- Date:
- Tue May 07 17:50:58 2019 +0000
- Revision:
- 28:d0b0a64a832d
- Parent:
- 26:6427f09cf8d3
- Child:
- 29:f7a2d2a755ec
Documented the bat and ball class;
Who changed what in which revision?
User | Revision | Line number | New 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 | 26:6427f09cf8d3 | 12 | @author Shahid Zubin Sajid |
shahidsajid | 28:d0b0a64a832d | 13 | @brief GAME ENGINE FOR HERO CRICKET |
shahidsajid | 26:6427f09cf8d3 | 14 | @date May 2019 |
shahidsajid | 10:6c6e09023942 | 15 | */ |
shahidsajid | 10:6c6e09023942 | 16 | class Cricket |
shahidsajid | 10:6c6e09023942 | 17 | { |
shahidsajid | 10:6c6e09023942 | 18 | |
shahidsajid | 10:6c6e09023942 | 19 | public: |
shahidsajid | 28:d0b0a64a832d | 20 | |
shahidsajid | 10:6c6e09023942 | 21 | Cricket(); |
shahidsajid | 10:6c6e09023942 | 22 | ~Cricket(); |
shahidsajid | 28:d0b0a64a832d | 23 | /** |
shahidsajid | 28:d0b0a64a832d | 24 | * @brief Initlialises the Cricket class Object |
shahidsajid | 28:d0b0a64a832d | 25 | * @details Intialises the bat variables to the starting values |
shahidsajid | 28:d0b0a64a832d | 26 | * @details Initialises the other class objects used in the game |
shahidsajid | 28:d0b0a64a832d | 27 | */ |
shahidsajid | 10:6c6e09023942 | 28 | void init(); |
shahidsajid | 28:d0b0a64a832d | 29 | /** |
shahidsajid | 28:d0b0a64a832d | 30 | * @brief Draws the fielders, the outfield circle and the pitch onto the LCD |
shahidsajid | 28:d0b0a64a832d | 31 | */ |
shahidsajid | 10:6c6e09023942 | 32 | void draw(N5110 &lcd); |
shahidsajid | 26:6427f09cf8d3 | 33 | |
shahidsajid | 26:6427f09cf8d3 | 34 | //Setters |
shahidsajid | 10:6c6e09023942 | 35 | void set_field(N5110 &lcd); |
shahidsajid | 28:d0b0a64a832d | 36 | /** |
shahidsajid | 28:d0b0a64a832d | 37 | * @brief Method to set the cor-dinates,direction and position for batsman to hit the ball |
shahidsajid | 28:d0b0a64a832d | 38 | * @param x @details Integer value for the x-cordinate |
shahidsajid | 28:d0b0a64a832d | 39 | * @param y @details Integer value for the y-cordinate |
shahidsajid | 28:d0b0a64a832d | 40 | * @param direction @details Direction variable to set the position direction |
shahidsajid | 28:d0b0a64a832d | 41 | * @param no @details integer to store the position number |
shahidsajid | 28:d0b0a64a832d | 42 | */ |
shahidsajid | 13:924891519a95 | 43 | void set_init_positions(int x,int y, Direction direction,int no); |
shahidsajid | 28:d0b0a64a832d | 44 | /** |
shahidsajid | 28:d0b0a64a832d | 45 | * @brief Sets the ball direction and sets _direction_set to 1 |
shahidsajid | 28:d0b0a64a832d | 46 | * @details loops through the positions available and sets the direction to the arguement if found |
shahidsajid | 28:d0b0a64a832d | 47 | * @param dir @details Direction variable recieved as recived from the joystick during gameplay |
shahidsajid | 28:d0b0a64a832d | 48 | */ |
shahidsajid | 28:d0b0a64a832d | 49 | void set_ball_direction(Direction dir); |
shahidsajid | 28:d0b0a64a832d | 50 | /** |
shahidsajid | 28:d0b0a64a832d | 51 | * @brief Draws the 5 outfield filders to the LCD |
shahidsajid | 28:d0b0a64a832d | 52 | * @details Loops through the fielders array and prints the fielders acc. to their cordinates |
shahidsajid | 28:d0b0a64a832d | 53 | * param &lcd @details reference pointer for the LCD |
shahidsajid | 28:d0b0a64a832d | 54 | */ |
shahidsajid | 10:6c6e09023942 | 55 | void draw_field(N5110 &lcd); |
shahidsajid | 28:d0b0a64a832d | 56 | /** |
shahidsajid | 28:d0b0a64a832d | 57 | * @brief Method to set the cor-dinates,direction and position for batsman to hit the ball |
shahidsajid | 28:d0b0a64a832d | 58 | * @param x @details Integer value for the x-cordinate |
shahidsajid | 28:d0b0a64a832d | 59 | * @param y @details Integer value for the y-cordinate |
shahidsajid | 28:d0b0a64a832d | 60 | * @param direction @details Direction variable to set the position direction |
shahidsajid | 28:d0b0a64a832d | 61 | * @param no @details integer to store the position number |
shahidsajid | 28:d0b0a64a832d | 62 | */ |
shahidsajid | 19:e1ded5acb64a | 63 | void update_game(int checkHit,int loft_check, Direction dir,Gamepad &pad,N5110 &lcd); |
shahidsajid | 11:f481ec642cc5 | 64 | void play_game(N5110 &lcd,Gamepad &pad); |
shahidsajid | 28:d0b0a64a832d | 65 | /** |
shahidsajid | 28:d0b0a64a832d | 66 | * @brief Updates the score by adding runs scored during the round to score |
shahidsajid | 28:d0b0a64a832d | 67 | * @param checkUpdate @details integer value which validates that the game has been updated |
shahidsajid | 28:d0b0a64a832d | 68 | * @param runs @details Integer value which stores the runs scored during the round |
shahidsajid | 28:d0b0a64a832d | 69 | * @param &pad @details Takes a reference pointer to a Gamepad object |
shahidsajid | 28:d0b0a64a832d | 70 | */ |
shahidsajid | 28:d0b0a64a832d | 71 | void update_scoreboard(int checkUpdate,int runs, Gamepad &pad); |
shahidsajid | 28:d0b0a64a832d | 72 | /** |
shahidsajid | 28:d0b0a64a832d | 73 | * @brief method when a batsman is out, screen updates and game resets. |
shahidsajid | 28:d0b0a64a832d | 74 | * @param option @details integer value which identifies the way batsman is out |
shahidsajid | 28:d0b0a64a832d | 75 | * @param &pad @details Takes a reference pointer to a Gamepad object |
shahidsajid | 28:d0b0a64a832d | 76 | * @param &lcd @details reference pointer for the LCD |
shahidsajid | 28:d0b0a64a832d | 77 | */ |
shahidsajid | 19:e1ded5acb64a | 78 | void batsman_out(int option,Gamepad &pad, N5110 &lcd); |
shahidsajid | 28:d0b0a64a832d | 79 | /** |
shahidsajid | 28:d0b0a64a832d | 80 | * @brief method which compares score and target, if true game is won and game resets |
shahidsajid | 28:d0b0a64a832d | 81 | * @param &lcd @details reference pointer for the LCD |
shahidsajid | 28:d0b0a64a832d | 82 | */ |
shahidsajid | 18:a260ce8db9e7 | 83 | void check_victory(N5110 &lcd); |
shahidsajid | 28:d0b0a64a832d | 84 | |
shahidsajid | 19:e1ded5acb64a | 85 | void game(N5110 &lcd,Gamepad &pad); |
shahidsajid | 24:23fd6b451db7 | 86 | void intro(N5110 &lcd); |
shahidsajid | 24:23fd6b451db7 | 87 | bool game_status(N5110 &lcd); |
shahidsajid | 24:23fd6b451db7 | 88 | void info_screen(N5110 &lcd, int target); |
shahidsajid | 19:e1ded5acb64a | 89 | |
shahidsajid | 12:954da4f4e565 | 90 | void init_positions(); |
shahidsajid | 19:e1ded5acb64a | 91 | void round_reset(); |
shahidsajid | 19:e1ded5acb64a | 92 | void game_reset(); |
shahidsajid | 13:924891519a95 | 93 | int check_fielder(Direction dir); |
shahidsajid | 19:e1ded5acb64a | 94 | bool check_ball_count(N5110 &lcd); |
shahidsajid | 10:6c6e09023942 | 95 | private: |
shahidsajid | 10:6c6e09023942 | 96 | Ball ball; |
shahidsajid | 10:6c6e09023942 | 97 | Bat bat; |
shahidsajid | 14:122eaa3b7a50 | 98 | Scoreboard scoreboard; |
shahidsajid | 21:a0904159e183 | 99 | UX ux; |
shahidsajid | 12:954da4f4e565 | 100 | |
shahidsajid | 12:954da4f4e565 | 101 | struct fielder_positions{ |
shahidsajid | 12:954da4f4e565 | 102 | Direction dir; |
shahidsajid | 12:954da4f4e565 | 103 | int x; |
shahidsajid | 12:954da4f4e565 | 104 | int y; |
shahidsajid | 12:954da4f4e565 | 105 | int no; |
shahidsajid | 12:954da4f4e565 | 106 | }; |
shahidsajid | 12:954da4f4e565 | 107 | fielder_positions positions[7]; |
shahidsajid | 10:6c6e09023942 | 108 | struct Fielder{ |
shahidsajid | 10:6c6e09023942 | 109 | Direction dir; |
shahidsajid | 10:6c6e09023942 | 110 | int x; |
shahidsajid | 10:6c6e09023942 | 111 | int y; |
shahidsajid | 10:6c6e09023942 | 112 | int position; |
shahidsajid | 10:6c6e09023942 | 113 | }; |
shahidsajid | 10:6c6e09023942 | 114 | Fielder field[5]; |
shahidsajid | 26:6427f09cf8d3 | 115 | |
shahidsajid | 26:6427f09cf8d3 | 116 | Direction _ball_direction; |
shahidsajid | 26:6427f09cf8d3 | 117 | int _check_bowled; |
shahidsajid | 26:6427f09cf8d3 | 118 | int _init_field_counter; |
shahidsajid | 26:6427f09cf8d3 | 119 | int _fielders_count; |
shahidsajid | 26:6427f09cf8d3 | 120 | int _new_round; |
shahidsajid | 26:6427f09cf8d3 | 121 | int field_numbers[10]; |
shahidsajid | 20:9d21599fe350 | 122 | int _position_no; |
shahidsajid | 10:6c6e09023942 | 123 | int ballHit; |
shahidsajid | 26:6427f09cf8d3 | 124 | int _ball_limit; |
shahidsajid | 26:6427f09cf8d3 | 125 | int _new_game; |
shahidsajid | 26:6427f09cf8d3 | 126 | int _check_update; |
shahidsajid | 26:6427f09cf8d3 | 127 | int _check_hit; |
shahidsajid | 26:6427f09cf8d3 | 128 | int _set_hit; |
shahidsajid | 26:6427f09cf8d3 | 129 | int _set_loft; |
shahidsajid | 26:6427f09cf8d3 | 130 | int _direction_set; |
shahidsajid | 26:6427f09cf8d3 | 131 | int _loft_check; |
shahidsajid | 26:6427f09cf8d3 | 132 | //int d; |
shahidsajid | 10:6c6e09023942 | 133 | }; |
shahidsajid | 10:6c6e09023942 | 134 | #endif |