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.cpp@26:6427f09cf8d3, 2019-05-01 (annotated)
- Committer:
- shahidsajid
- Date:
- Wed May 01 11:56:36 2019 +0000
- Revision:
- 26:6427f09cf8d3
- Parent:
- 25:ead0e7bd1569
- Child:
- 28:d0b0a64a832d
Documented the UX class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shahidsajid | 10:6c6e09023942 | 1 | #include "Cricket.h" |
shahidsajid | 10:6c6e09023942 | 2 | |
shahidsajid | 10:6c6e09023942 | 3 | |
shahidsajid | 10:6c6e09023942 | 4 | Cricket::Cricket() |
shahidsajid | 10:6c6e09023942 | 5 | { |
shahidsajid | 10:6c6e09023942 | 6 | |
shahidsajid | 10:6c6e09023942 | 7 | } |
shahidsajid | 10:6c6e09023942 | 8 | |
shahidsajid | 10:6c6e09023942 | 9 | Cricket::~Cricket() |
shahidsajid | 10:6c6e09023942 | 10 | { |
shahidsajid | 10:6c6e09023942 | 11 | |
shahidsajid | 10:6c6e09023942 | 12 | } |
shahidsajid | 10:6c6e09023942 | 13 | |
shahidsajid | 10:6c6e09023942 | 14 | void Cricket::init() |
shahidsajid | 10:6c6e09023942 | 15 | { |
shahidsajid | 21:a0904159e183 | 16 | ux.init(); |
shahidsajid | 10:6c6e09023942 | 17 | bat.init(4,5); |
shahidsajid | 10:6c6e09023942 | 18 | ball.init(2,3); |
shahidsajid | 14:122eaa3b7a50 | 19 | scoreboard.init(); |
shahidsajid | 26:6427f09cf8d3 | 20 | _new_round=1; |
shahidsajid | 26:6427f09cf8d3 | 21 | _direction_set=0; |
shahidsajid | 26:6427f09cf8d3 | 22 | _new_game=1; |
shahidsajid | 26:6427f09cf8d3 | 23 | _fielders_count=0; |
shahidsajid | 26:6427f09cf8d3 | 24 | _init_field_counter=0; |
shahidsajid | 12:954da4f4e565 | 25 | init_positions(); |
shahidsajid | 26:6427f09cf8d3 | 26 | _set_hit=0; |
shahidsajid | 26:6427f09cf8d3 | 27 | _set_loft=0; |
shahidsajid | 20:9d21599fe350 | 28 | _position_no=-1; |
shahidsajid | 26:6427f09cf8d3 | 29 | _check_bowled=0; |
shahidsajid | 18:a260ce8db9e7 | 30 | _ball_limit=3; |
shahidsajid | 26:6427f09cf8d3 | 31 | _check_hit=0; |
shahidsajid | 26:6427f09cf8d3 | 32 | _loft_check=0; |
shahidsajid | 26:6427f09cf8d3 | 33 | _check_update=-1; |
shahidsajid | 13:924891519a95 | 34 | } |
shahidsajid | 19:e1ded5acb64a | 35 | void Cricket::round_reset(){ |
shahidsajid | 14:122eaa3b7a50 | 36 | ball.reset(); |
shahidsajid | 14:122eaa3b7a50 | 37 | bat.reset(); |
shahidsajid | 26:6427f09cf8d3 | 38 | _new_round=0; |
shahidsajid | 26:6427f09cf8d3 | 39 | _direction_set=0; |
shahidsajid | 26:6427f09cf8d3 | 40 | _fielders_count=0; |
shahidsajid | 26:6427f09cf8d3 | 41 | _loft_check=0; |
shahidsajid | 26:6427f09cf8d3 | 42 | _check_hit=0; |
shahidsajid | 26:6427f09cf8d3 | 43 | _set_hit=0; |
shahidsajid | 15:81a3aaf52647 | 44 | ballHit=0; |
shahidsajid | 26:6427f09cf8d3 | 45 | _set_loft=0; |
shahidsajid | 26:6427f09cf8d3 | 46 | _init_field_counter=0; |
shahidsajid | 13:924891519a95 | 47 | init_positions(); |
shahidsajid | 20:9d21599fe350 | 48 | _position_no=-1; |
shahidsajid | 26:6427f09cf8d3 | 49 | _check_bowled=0; |
shahidsajid | 26:6427f09cf8d3 | 50 | _check_update=-1; |
shahidsajid | 19:e1ded5acb64a | 51 | } |
shahidsajid | 19:e1ded5acb64a | 52 | void Cricket::game_reset(){ |
shahidsajid | 24:23fd6b451db7 | 53 | //pad.leds_off(); |
shahidsajid | 19:e1ded5acb64a | 54 | round_reset(); |
shahidsajid | 26:6427f09cf8d3 | 55 | _new_game=1; |
shahidsajid | 19:e1ded5acb64a | 56 | scoreboard.reset(); |
shahidsajid | 19:e1ded5acb64a | 57 | ball.reset_ball_count(); |
shahidsajid | 10:6c6e09023942 | 58 | } |
shahidsajid | 24:23fd6b451db7 | 59 | void Cricket::intro(N5110 &lcd){ |
shahidsajid | 24:23fd6b451db7 | 60 | ux.first_menu(lcd); |
shahidsajid | 24:23fd6b451db7 | 61 | } |
shahidsajid | 11:f481ec642cc5 | 62 | void Cricket::game(N5110 &lcd,Gamepad &pad){ |
shahidsajid | 26:6427f09cf8d3 | 63 | if (_new_game==1){ |
shahidsajid | 24:23fd6b451db7 | 64 | printf("TEST 1\n"); |
shahidsajid | 18:a260ce8db9e7 | 65 | scoreboard.generate_target(); |
shahidsajid | 24:23fd6b451db7 | 66 | ux.second_menu(lcd); |
shahidsajid | 26:6427f09cf8d3 | 67 | _new_game=0; |
shahidsajid | 18:a260ce8db9e7 | 68 | } |
shahidsajid | 26:6427f09cf8d3 | 69 | if (_new_round==1){ |
shahidsajid | 25:ead0e7bd1569 | 70 | if (game_status(lcd)==false){ |
shahidsajid | 19:e1ded5acb64a | 71 | game_reset(); |
shahidsajid | 25:ead0e7bd1569 | 72 | ux.second_menu(lcd); |
shahidsajid | 25:ead0e7bd1569 | 73 | } |
shahidsajid | 19:e1ded5acb64a | 74 | else{ |
shahidsajid | 19:e1ded5acb64a | 75 | check_ball_count(lcd); |
shahidsajid | 19:e1ded5acb64a | 76 | pad.leds_off(); |
shahidsajid | 19:e1ded5acb64a | 77 | round_reset(); |
shahidsajid | 19:e1ded5acb64a | 78 | set_field(lcd); |
shahidsajid | 19:e1ded5acb64a | 79 | ball.increment_ball_count(); |
shahidsajid | 19:e1ded5acb64a | 80 | play_game(lcd,pad); |
shahidsajid | 26:6427f09cf8d3 | 81 | _new_round=0; |
shahidsajid | 19:e1ded5acb64a | 82 | } |
shahidsajid | 13:924891519a95 | 83 | } |
shahidsajid | 13:924891519a95 | 84 | else |
shahidsajid | 13:924891519a95 | 85 | play_game(lcd,pad); |
shahidsajid | 10:6c6e09023942 | 86 | } |
shahidsajid | 24:23fd6b451db7 | 87 | bool Cricket::game_status(N5110 &lcd){ |
shahidsajid | 24:23fd6b451db7 | 88 | if (scoreboard.compare_target()==true){ |
shahidsajid | 24:23fd6b451db7 | 89 | printf("COMING FROM HERE"); |
shahidsajid | 24:23fd6b451db7 | 90 | ux.victory_menu(lcd); |
shahidsajid | 24:23fd6b451db7 | 91 | game_reset(); |
shahidsajid | 24:23fd6b451db7 | 92 | return false; |
shahidsajid | 24:23fd6b451db7 | 93 | //} |
shahidsajid | 24:23fd6b451db7 | 94 | } |
shahidsajid | 24:23fd6b451db7 | 95 | else if(check_ball_count(lcd)==true){ |
shahidsajid | 24:23fd6b451db7 | 96 | ux.game_over_menu(lcd,1); |
shahidsajid | 24:23fd6b451db7 | 97 | game_reset(); |
shahidsajid | 24:23fd6b451db7 | 98 | return false; |
shahidsajid | 24:23fd6b451db7 | 99 | } |
shahidsajid | 24:23fd6b451db7 | 100 | else{ |
shahidsajid | 24:23fd6b451db7 | 101 | return true; |
shahidsajid | 24:23fd6b451db7 | 102 | } |
shahidsajid | 24:23fd6b451db7 | 103 | } |
shahidsajid | 24:23fd6b451db7 | 104 | |
shahidsajid | 19:e1ded5acb64a | 105 | bool Cricket::check_ball_count(N5110 &lcd){ |
shahidsajid | 18:a260ce8db9e7 | 106 | int count=ball.get_ball_count(); |
shahidsajid | 18:a260ce8db9e7 | 107 | if (count==_ball_limit){ |
shahidsajid | 26:6427f09cf8d3 | 108 | _new_round=1; |
shahidsajid | 18:a260ce8db9e7 | 109 | ball.reset_ball_count(); |
shahidsajid | 26:6427f09cf8d3 | 110 | _new_game=1; |
shahidsajid | 19:e1ded5acb64a | 111 | return true; |
shahidsajid | 19:e1ded5acb64a | 112 | } |
shahidsajid | 19:e1ded5acb64a | 113 | else{ |
shahidsajid | 19:e1ded5acb64a | 114 | return false; |
shahidsajid | 18:a260ce8db9e7 | 115 | } |
shahidsajid | 18:a260ce8db9e7 | 116 | } |
shahidsajid | 18:a260ce8db9e7 | 117 | void Cricket::check_victory(N5110 &lcd){ |
shahidsajid | 18:a260ce8db9e7 | 118 | bool _victory_check=scoreboard.compare_target(); |
shahidsajid | 18:a260ce8db9e7 | 119 | if (_victory_check==true){ |
shahidsajid | 21:a0904159e183 | 120 | ux.victory_menu(lcd); |
shahidsajid | 26:6427f09cf8d3 | 121 | _new_game=1; |
shahidsajid | 18:a260ce8db9e7 | 122 | ball.reset_ball_count(); |
shahidsajid | 18:a260ce8db9e7 | 123 | } |
shahidsajid | 18:a260ce8db9e7 | 124 | } |
shahidsajid | 12:954da4f4e565 | 125 | void Cricket::init_positions(){ |
shahidsajid | 20:9d21599fe350 | 126 | set_init_positions(42,15,N,1); |
shahidsajid | 15:81a3aaf52647 | 127 | set_init_positions(84,30,E,2); |
shahidsajid | 15:81a3aaf52647 | 128 | set_init_positions(0,30,W,3); |
shahidsajid | 15:81a3aaf52647 | 129 | set_init_positions(2,44,SW,4); |
shahidsajid | 15:81a3aaf52647 | 130 | set_init_positions(0,2,NW,5); |
shahidsajid | 20:9d21599fe350 | 131 | set_init_positions(65,2,NE,6); |
shahidsajid | 15:81a3aaf52647 | 132 | set_init_positions(60,44,SE,7); |
shahidsajid | 12:954da4f4e565 | 133 | } |
shahidsajid | 21:a0904159e183 | 134 | |
shahidsajid | 12:954da4f4e565 | 135 | void Cricket::set_init_positions(int x,int y, Direction direction,int no){ |
shahidsajid | 26:6427f09cf8d3 | 136 | positions[_init_field_counter].x=x; |
shahidsajid | 26:6427f09cf8d3 | 137 | positions[_init_field_counter].y=y; |
shahidsajid | 26:6427f09cf8d3 | 138 | positions[_init_field_counter].dir=direction; |
shahidsajid | 26:6427f09cf8d3 | 139 | positions[_init_field_counter].no=no; |
shahidsajid | 26:6427f09cf8d3 | 140 | _init_field_counter++; |
shahidsajid | 12:954da4f4e565 | 141 | } |
shahidsajid | 11:f481ec642cc5 | 142 | void Cricket::play_game(N5110 &lcd,Gamepad &pad){ |
shahidsajid | 26:6427f09cf8d3 | 143 | _check_hit=bat.get_hitBall(ux); |
shahidsajid | 26:6427f09cf8d3 | 144 | if (_check_hit==1){ |
shahidsajid | 26:6427f09cf8d3 | 145 | _set_hit=1; |
shahidsajid | 21:a0904159e183 | 146 | } |
shahidsajid | 26:6427f09cf8d3 | 147 | _loft_check=bat.get_loft_ball(ux); |
shahidsajid | 26:6427f09cf8d3 | 148 | if (_loft_check==1){ |
shahidsajid | 26:6427f09cf8d3 | 149 | _set_loft=1; |
shahidsajid | 24:23fd6b451db7 | 150 | } |
shahidsajid | 12:954da4f4e565 | 151 | Direction dir=pad.get_direction(); |
shahidsajid | 26:6427f09cf8d3 | 152 | if (_check_bowled!=1){ |
shahidsajid | 26:6427f09cf8d3 | 153 | _check_bowled=ball.ball_start(pad); |
shahidsajid | 12:954da4f4e565 | 154 | } |
shahidsajid | 12:954da4f4e565 | 155 | else{ |
shahidsajid | 26:6427f09cf8d3 | 156 | update_game(_set_hit, _set_loft, dir,pad,lcd); |
shahidsajid | 12:954da4f4e565 | 157 | } |
shahidsajid | 11:f481ec642cc5 | 158 | } |
shahidsajid | 19:e1ded5acb64a | 159 | void Cricket::update_game(int checkHit,int loft_check, Direction dir,Gamepad &pad,N5110 &lcd){ |
shahidsajid | 13:924891519a95 | 160 | set_ball_direction(dir); |
shahidsajid | 26:6427f09cf8d3 | 161 | int fielder_check=check_fielder(_ball_direction); |
shahidsajid | 15:81a3aaf52647 | 162 | if (checkHit!=1) |
shahidsajid | 21:a0904159e183 | 163 | batsman_out(2,pad,lcd); |
shahidsajid | 26:6427f09cf8d3 | 164 | if(_direction_set==1 && checkHit==1){ |
shahidsajid | 13:924891519a95 | 165 | if (fielder_check!=-1){ |
shahidsajid | 26:6427f09cf8d3 | 166 | _check_update=ball.update_ball(field[fielder_check].x,field[fielder_check].y); |
shahidsajid | 15:81a3aaf52647 | 167 | printf("Location x %i y %i\n",field[fielder_check].x,field[fielder_check].y); |
shahidsajid | 15:81a3aaf52647 | 168 | if (loft_check==1){ |
shahidsajid | 26:6427f09cf8d3 | 169 | if (_check_update==1) |
shahidsajid | 19:e1ded5acb64a | 170 | batsman_out(3,pad,lcd); |
shahidsajid | 13:924891519a95 | 171 | } |
shahidsajid | 15:81a3aaf52647 | 172 | else |
shahidsajid | 26:6427f09cf8d3 | 173 | update_scoreboard(_check_update,field[fielder_check].position+1,pad); |
shahidsajid | 13:924891519a95 | 174 | } |
shahidsajid | 13:924891519a95 | 175 | if (fielder_check==-1){ |
shahidsajid | 26:6427f09cf8d3 | 176 | _check_update=ball.update_ball(positions[_position_no].x,positions[_position_no].y); |
shahidsajid | 26:6427f09cf8d3 | 177 | printf("location x %i y %i\n update %i\n",positions[_position_no].x,positions[_position_no].y,_check_update); |
shahidsajid | 15:81a3aaf52647 | 178 | if (loft_check==1) |
shahidsajid | 26:6427f09cf8d3 | 179 | update_scoreboard(_check_update,6,pad); |
shahidsajid | 15:81a3aaf52647 | 180 | else |
shahidsajid | 26:6427f09cf8d3 | 181 | update_scoreboard(_check_update,4,pad); |
shahidsajid | 13:924891519a95 | 182 | } |
shahidsajid | 15:81a3aaf52647 | 183 | } |
shahidsajid | 15:81a3aaf52647 | 184 | } |
shahidsajid | 15:81a3aaf52647 | 185 | void Cricket::update_scoreboard(int checkUpdate, int runs,Gamepad &pad){ |
shahidsajid | 15:81a3aaf52647 | 186 | if (checkUpdate==1){ |
shahidsajid | 26:6427f09cf8d3 | 187 | if (_ball_direction==N){ |
shahidsajid | 20:9d21599fe350 | 188 | scoreboard.update_score(0); |
shahidsajid | 20:9d21599fe350 | 189 | pad.led(3,1.0); |
shahidsajid | 20:9d21599fe350 | 190 | wait(0.5); |
shahidsajid | 26:6427f09cf8d3 | 191 | _new_round=1; |
shahidsajid | 20:9d21599fe350 | 192 | } |
shahidsajid | 20:9d21599fe350 | 193 | else{ |
shahidsajid | 20:9d21599fe350 | 194 | scoreboard.update_score(runs); |
shahidsajid | 20:9d21599fe350 | 195 | pad.led(3,1.0); |
shahidsajid | 20:9d21599fe350 | 196 | wait(0.5); |
shahidsajid | 26:6427f09cf8d3 | 197 | _new_round=1; |
shahidsajid | 20:9d21599fe350 | 198 | } |
shahidsajid | 14:122eaa3b7a50 | 199 | } |
shahidsajid | 24:23fd6b451db7 | 200 | pad.leds_off(); |
shahidsajid | 13:924891519a95 | 201 | } |
shahidsajid | 20:9d21599fe350 | 202 | |
shahidsajid | 19:e1ded5acb64a | 203 | void Cricket::batsman_out(int option,Gamepad &pad, N5110 &lcd){ |
shahidsajid | 15:81a3aaf52647 | 204 | scoreboard.reset(); |
shahidsajid | 15:81a3aaf52647 | 205 | pad.led(1,1.0); |
shahidsajid | 18:a260ce8db9e7 | 206 | //pad.tone(750.0,0.5); |
shahidsajid | 19:e1ded5acb64a | 207 | ball.reset_ball_count(); |
shahidsajid | 21:a0904159e183 | 208 | ux.game_over_menu(lcd,option); |
shahidsajid | 24:23fd6b451db7 | 209 | game_reset(); |
shahidsajid | 26:6427f09cf8d3 | 210 | _new_game=1; |
shahidsajid | 15:81a3aaf52647 | 211 | wait(2); |
shahidsajid | 24:23fd6b451db7 | 212 | pad.leds_off(); |
shahidsajid | 25:ead0e7bd1569 | 213 | ux.second_menu(lcd); |
shahidsajid | 15:81a3aaf52647 | 214 | } |
shahidsajid | 13:924891519a95 | 215 | void Cricket::draw(N5110 &lcd){ |
shahidsajid | 13:924891519a95 | 216 | lcd.drawCircle((WIDTH/2),HEIGHT/2,23,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 217 | lcd.drawRect(37,11,12,30,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 218 | ball.draw(lcd); |
shahidsajid | 13:924891519a95 | 219 | draw_field(lcd); |
shahidsajid | 13:924891519a95 | 220 | bat.draw(lcd); |
shahidsajid | 14:122eaa3b7a50 | 221 | scoreboard.draw(lcd); |
shahidsajid | 13:924891519a95 | 222 | } |
shahidsajid | 13:924891519a95 | 223 | void Cricket::set_ball_direction(Direction dir){ |
shahidsajid | 26:6427f09cf8d3 | 224 | if (_direction_set!=1){ |
shahidsajid | 26:6427f09cf8d3 | 225 | for (int i=0;i<_init_field_counter+1;i++){ |
shahidsajid | 20:9d21599fe350 | 226 | if(dir==positions[i].dir){ |
shahidsajid | 26:6427f09cf8d3 | 227 | _ball_direction=dir; |
shahidsajid | 20:9d21599fe350 | 228 | printf(" BALL DIRECTION %i x %i y %i \n",positions[i].no,positions[i].x,positions[i].y); |
shahidsajid | 20:9d21599fe350 | 229 | _position_no=i; |
shahidsajid | 26:6427f09cf8d3 | 230 | _direction_set=1; |
shahidsajid | 20:9d21599fe350 | 231 | break; |
shahidsajid | 20:9d21599fe350 | 232 | } |
shahidsajid | 20:9d21599fe350 | 233 | } |
shahidsajid | 12:954da4f4e565 | 234 | } |
shahidsajid | 12:954da4f4e565 | 235 | } |
shahidsajid | 13:924891519a95 | 236 | int Cricket::check_fielder(Direction dir){ |
shahidsajid | 13:924891519a95 | 237 | Vector2D p; |
shahidsajid | 20:9d21599fe350 | 238 | if (dir==N){ |
shahidsajid | 20:9d21599fe350 | 239 | return -1; |
shahidsajid | 20:9d21599fe350 | 240 | } |
shahidsajid | 15:81a3aaf52647 | 241 | for (int i=0;i<8;i++){ |
shahidsajid | 13:924891519a95 | 242 | if(dir == field[i].dir){ |
shahidsajid | 13:924891519a95 | 243 | return i; |
shahidsajid | 13:924891519a95 | 244 | } |
shahidsajid | 13:924891519a95 | 245 | } |
shahidsajid | 13:924891519a95 | 246 | return -1; |
shahidsajid | 10:6c6e09023942 | 247 | } |
shahidsajid | 10:6c6e09023942 | 248 | void Cricket::draw_field(N5110 &lcd){ |
shahidsajid | 13:924891519a95 | 249 | lcd.drawCircle(field[0].x,field[0].y,2,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 250 | lcd.drawCircle(field[1].x,field[1].y,2,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 251 | lcd.drawCircle(field[2].x,field[2].y,2,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 252 | lcd.drawCircle(field[3].x,field[3].y,2,FILL_TRANSPARENT); |
shahidsajid | 14:122eaa3b7a50 | 253 | lcd.drawCircle(field[4].x,field[4].y,2,FILL_TRANSPARENT); |
shahidsajid | 10:6c6e09023942 | 254 | } |
shahidsajid | 10:6c6e09023942 | 255 | void Cricket::set_field(N5110 &lcd){ |
shahidsajid | 10:6c6e09023942 | 256 | int d=0; |
shahidsajid | 10:6c6e09023942 | 257 | int pos=0; |
shahidsajid | 10:6c6e09023942 | 258 | int i=0; |
shahidsajid | 10:6c6e09023942 | 259 | int continueCount=0; |
shahidsajid | 10:6c6e09023942 | 260 | srand(time(NULL)); |
shahidsajid | 26:6427f09cf8d3 | 261 | while (_fielders_count!=5){ |
shahidsajid | 10:6c6e09023942 | 262 | d = 1+ rand() % 6; |
shahidsajid | 10:6c6e09023942 | 263 | pos=rand()%2; |
shahidsajid | 10:6c6e09023942 | 264 | for (int j=0;j<10;j++){ |
shahidsajid | 26:6427f09cf8d3 | 265 | if (field_numbers[j]==d){ |
shahidsajid | 10:6c6e09023942 | 266 | continueCount=1; |
shahidsajid | 10:6c6e09023942 | 267 | } |
shahidsajid | 10:6c6e09023942 | 268 | } |
shahidsajid | 10:6c6e09023942 | 269 | if (continueCount==1){ |
shahidsajid | 10:6c6e09023942 | 270 | continueCount=0; |
shahidsajid | 10:6c6e09023942 | 271 | continue; |
shahidsajid | 10:6c6e09023942 | 272 | } |
shahidsajid | 10:6c6e09023942 | 273 | if (d==1){ //NW |
shahidsajid | 10:6c6e09023942 | 274 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 275 | field[i].dir=NW; |
shahidsajid | 10:6c6e09023942 | 276 | field[i].x=30; |
shahidsajid | 10:6c6e09023942 | 277 | field[i].y=9; |
shahidsajid | 10:6c6e09023942 | 278 | field[i].position=1; |
shahidsajid | 26:6427f09cf8d3 | 279 | field_numbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 280 | i++; |
shahidsajid | 26:6427f09cf8d3 | 281 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 282 | } |
shahidsajid | 10:6c6e09023942 | 283 | else{ |
shahidsajid | 10:6c6e09023942 | 284 | field[i].dir=NW; |
shahidsajid | 10:6c6e09023942 | 285 | field[i].x=25; |
shahidsajid | 10:6c6e09023942 | 286 | field[i].y=2; |
shahidsajid | 10:6c6e09023942 | 287 | field[i].position=0; |
shahidsajid | 26:6427f09cf8d3 | 288 | field_numbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 289 | i++; |
shahidsajid | 26:6427f09cf8d3 | 290 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 291 | } |
shahidsajid | 10:6c6e09023942 | 292 | } |
shahidsajid | 10:6c6e09023942 | 293 | |
shahidsajid | 10:6c6e09023942 | 294 | |
shahidsajid | 10:6c6e09023942 | 295 | if (d==2){ //NE |
shahidsajid | 10:6c6e09023942 | 296 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 297 | field[i].dir=NE; |
shahidsajid | 10:6c6e09023942 | 298 | field[i].x=55; |
shahidsajid | 10:6c6e09023942 | 299 | field[i].y=9; |
shahidsajid | 10:6c6e09023942 | 300 | field[i].position=1; |
shahidsajid | 26:6427f09cf8d3 | 301 | field_numbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 302 | i++; |
shahidsajid | 26:6427f09cf8d3 | 303 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 304 | } |
shahidsajid | 10:6c6e09023942 | 305 | else{ |
shahidsajid | 10:6c6e09023942 | 306 | field[i].dir=NE; |
shahidsajid | 10:6c6e09023942 | 307 | field[i].x=65; |
shahidsajid | 10:6c6e09023942 | 308 | field[i].y=2; |
shahidsajid | 10:6c6e09023942 | 309 | field[i].position=0; |
shahidsajid | 26:6427f09cf8d3 | 310 | field_numbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 311 | i++; |
shahidsajid | 26:6427f09cf8d3 | 312 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 313 | } |
shahidsajid | 10:6c6e09023942 | 314 | } |
shahidsajid | 10:6c6e09023942 | 315 | |
shahidsajid | 10:6c6e09023942 | 316 | |
shahidsajid | 10:6c6e09023942 | 317 | if (d==3){ //SW |
shahidsajid | 10:6c6e09023942 | 318 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 319 | field[i].dir=SW; |
shahidsajid | 10:6c6e09023942 | 320 | field[i].x=33; |
shahidsajid | 10:6c6e09023942 | 321 | field[i].y=40; |
shahidsajid | 10:6c6e09023942 | 322 | field[i].position=1; |
shahidsajid | 26:6427f09cf8d3 | 323 | field_numbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 324 | i++; |
shahidsajid | 26:6427f09cf8d3 | 325 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 326 | } |
shahidsajid | 10:6c6e09023942 | 327 | |
shahidsajid | 10:6c6e09023942 | 328 | else{ |
shahidsajid | 10:6c6e09023942 | 329 | field[i].dir=SW; |
shahidsajid | 10:6c6e09023942 | 330 | field[i].x=25; |
shahidsajid | 10:6c6e09023942 | 331 | field[i].y=44; |
shahidsajid | 10:6c6e09023942 | 332 | field[i].position=0; |
shahidsajid | 26:6427f09cf8d3 | 333 | field_numbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 334 | i++; |
shahidsajid | 26:6427f09cf8d3 | 335 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 336 | } |
shahidsajid | 10:6c6e09023942 | 337 | } |
shahidsajid | 10:6c6e09023942 | 338 | |
shahidsajid | 10:6c6e09023942 | 339 | if (d==4){ //SE |
shahidsajid | 10:6c6e09023942 | 340 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 341 | field[i].dir=SE; |
shahidsajid | 10:6c6e09023942 | 342 | field[i].x=55; |
shahidsajid | 10:6c6e09023942 | 343 | field[i].y=40; |
shahidsajid | 10:6c6e09023942 | 344 | field[i].position=1; |
shahidsajid | 26:6427f09cf8d3 | 345 | field_numbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 346 | i++; |
shahidsajid | 26:6427f09cf8d3 | 347 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 348 | } |
shahidsajid | 10:6c6e09023942 | 349 | else{ |
shahidsajid | 10:6c6e09023942 | 350 | field[i].dir=SE; |
shahidsajid | 10:6c6e09023942 | 351 | field[i].x=65; |
shahidsajid | 10:6c6e09023942 | 352 | field[i].y=44; |
shahidsajid | 10:6c6e09023942 | 353 | field[i].position=0; |
shahidsajid | 26:6427f09cf8d3 | 354 | field_numbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 355 | i++; |
shahidsajid | 26:6427f09cf8d3 | 356 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 357 | } |
shahidsajid | 10:6c6e09023942 | 358 | } |
shahidsajid | 10:6c6e09023942 | 359 | |
shahidsajid | 10:6c6e09023942 | 360 | if (d==5){ //W |
shahidsajid | 10:6c6e09023942 | 361 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 362 | field[i].dir=W; |
shahidsajid | 10:6c6e09023942 | 363 | field[i].x=3; |
shahidsajid | 15:81a3aaf52647 | 364 | field[i].y=30; |
shahidsajid | 10:6c6e09023942 | 365 | field[i].position=1; |
shahidsajid | 26:6427f09cf8d3 | 366 | field_numbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 367 | i++; |
shahidsajid | 26:6427f09cf8d3 | 368 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 369 | } |
shahidsajid | 10:6c6e09023942 | 370 | else{ |
shahidsajid | 10:6c6e09023942 | 371 | field[i].dir=W; |
shahidsajid | 10:6c6e09023942 | 372 | field[i].x=25; |
shahidsajid | 15:81a3aaf52647 | 373 | field[i].y=30; |
shahidsajid | 10:6c6e09023942 | 374 | field[i].position=0; |
shahidsajid | 26:6427f09cf8d3 | 375 | field_numbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 376 | i++; |
shahidsajid | 26:6427f09cf8d3 | 377 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 378 | } |
shahidsajid | 13:924891519a95 | 379 | } |
shahidsajid | 10:6c6e09023942 | 380 | if (d==6){ //W |
shahidsajid | 10:6c6e09023942 | 381 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 382 | field[i].dir=E; |
shahidsajid | 10:6c6e09023942 | 383 | field[i].x=80; |
shahidsajid | 15:81a3aaf52647 | 384 | field[i].y=30; |
shahidsajid | 10:6c6e09023942 | 385 | field[i].position=1; |
shahidsajid | 26:6427f09cf8d3 | 386 | field_numbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 387 | i++; |
shahidsajid | 26:6427f09cf8d3 | 388 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 389 | } |
shahidsajid | 10:6c6e09023942 | 390 | else{ |
shahidsajid | 10:6c6e09023942 | 391 | field[i].dir=E; |
shahidsajid | 15:81a3aaf52647 | 392 | field[i].x=60; |
shahidsajid | 15:81a3aaf52647 | 393 | field[i].y=30; |
shahidsajid | 15:81a3aaf52647 | 394 | field[i].position=0; |
shahidsajid | 26:6427f09cf8d3 | 395 | field_numbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 396 | i++; |
shahidsajid | 26:6427f09cf8d3 | 397 | _fielders_count++; |
shahidsajid | 13:924891519a95 | 398 | } |
shahidsajid | 10:6c6e09023942 | 399 | } |
shahidsajid | 10:6c6e09023942 | 400 | } |
shahidsajid | 24:23fd6b451db7 | 401 | } |
shahidsajid | 24:23fd6b451db7 | 402 | void Cricket::info_screen(N5110 &lcd,int target){ |
shahidsajid | 24:23fd6b451db7 | 403 | lcd.clear(); |
shahidsajid | 24:23fd6b451db7 | 404 | lcd.printString("YOU ARE GIVEN",2,1); |
shahidsajid | 24:23fd6b451db7 | 405 | lcd.printString("10 BALLS ",3,2); |
shahidsajid | 24:23fd6b451db7 | 406 | lcd.refresh(); |
shahidsajid | 24:23fd6b451db7 | 407 | wait(0.5); |
shahidsajid | 24:23fd6b451db7 | 408 | char buffer[5]; |
shahidsajid | 24:23fd6b451db7 | 409 | int length=sprintf(buffer,"SCORE %i RUNS",target); |
shahidsajid | 24:23fd6b451db7 | 410 | lcd.printString(buffer,2,4); |
shahidsajid | 24:23fd6b451db7 | 411 | lcd.refresh(); |
shahidsajid | 24:23fd6b451db7 | 412 | wait(0.5); |
shahidsajid | 24:23fd6b451db7 | 413 | lcd.printString("GOOD LUCK!!!",0,5); |
shahidsajid | 24:23fd6b451db7 | 414 | lcd.refresh(); |
shahidsajid | 24:23fd6b451db7 | 415 | wait(3); |
shahidsajid | 24:23fd6b451db7 | 416 | } |
shahidsajid | 10:6c6e09023942 | 417 | |
shahidsajid | 10:6c6e09023942 | 418 |