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