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@30:43aace0fdbdf, 2019-05-08 (annotated)
- Committer:
- shahidsajid
- Date:
- Wed May 08 01:20:06 2019 +0000
- Revision:
- 30:43aace0fdbdf
- Parent:
- 29:f7a2d2a755ec
- Child:
- 31:eefa1d23a843
Updated in-line comments for 3 classes;
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 | 30:43aace0fdbdf | 16 | _ux.init(); |
shahidsajid | 30:43aace0fdbdf | 17 | _bat.init(4,5); |
shahidsajid | 30:43aace0fdbdf | 18 | _ball.init(2,3); |
shahidsajid | 30:43aace0fdbdf | 19 | _scoreboard.init(); |
shahidsajid | 26:6427f09cf8d3 | 20 | _new_round=1; |
shahidsajid | 30:43aace0fdbdf | 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 | 30:43aace0fdbdf | 36 | _ball.reset(); |
shahidsajid | 30:43aace0fdbdf | 37 | _bat.reset(); |
shahidsajid | 26:6427f09cf8d3 | 38 | _new_round=0; |
shahidsajid | 30:43aace0fdbdf | 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 | 30:43aace0fdbdf | 44 | _set_loft= |
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 | 30:43aace0fdbdf | 53 | _ux.reset(); |
shahidsajid | 19:e1ded5acb64a | 54 | round_reset(); |
shahidsajid | 26:6427f09cf8d3 | 55 | _new_game=1; |
shahidsajid | 30:43aace0fdbdf | 56 | _scoreboard.reset(); |
shahidsajid | 30:43aace0fdbdf | 57 | _ball.reset_ball_count(); |
shahidsajid | 10:6c6e09023942 | 58 | } |
shahidsajid | 24:23fd6b451db7 | 59 | void Cricket::intro(N5110 &lcd){ |
shahidsajid | 30:43aace0fdbdf | 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 | 30:43aace0fdbdf | 65 | _scoreboard.generate_target(); |
shahidsajid | 30:43aace0fdbdf | 66 | _ux.second_menu(lcd); |
shahidsajid | 30:43aace0fdbdf | 67 | _new_game=0; |
shahidsajid | 18:a260ce8db9e7 | 68 | } |
shahidsajid | 30:43aace0fdbdf | 69 | if (_new_round==1){ |
shahidsajid | 25:ead0e7bd1569 | 70 | if (game_status(lcd)==false){ |
shahidsajid | 19:e1ded5acb64a | 71 | game_reset(); |
shahidsajid | 30:43aace0fdbdf | 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 | 30:43aace0fdbdf | 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 | 30:43aace0fdbdf | 88 | if (_scoreboard.compare_target()==true){ |
shahidsajid | 24:23fd6b451db7 | 89 | printf("COMING FROM HERE"); |
shahidsajid | 30:43aace0fdbdf | 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 | 30:43aace0fdbdf | 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 | 19:e1ded5acb64a | 104 | bool Cricket::check_ball_count(N5110 &lcd){ |
shahidsajid | 30:43aace0fdbdf | 105 | int count=_ball.get_ball_count(); |
shahidsajid | 18:a260ce8db9e7 | 106 | if (count==_ball_limit){ |
shahidsajid | 26:6427f09cf8d3 | 107 | _new_round=1; |
shahidsajid | 30:43aace0fdbdf | 108 | _ball.reset_ball_count(); |
shahidsajid | 26:6427f09cf8d3 | 109 | _new_game=1; |
shahidsajid | 19:e1ded5acb64a | 110 | return true; |
shahidsajid | 19:e1ded5acb64a | 111 | } |
shahidsajid | 19:e1ded5acb64a | 112 | else{ |
shahidsajid | 19:e1ded5acb64a | 113 | return false; |
shahidsajid | 18:a260ce8db9e7 | 114 | } |
shahidsajid | 18:a260ce8db9e7 | 115 | } |
shahidsajid | 18:a260ce8db9e7 | 116 | void Cricket::check_victory(N5110 &lcd){ |
shahidsajid | 30:43aace0fdbdf | 117 | bool _victory_check=_scoreboard.compare_target(); |
shahidsajid | 18:a260ce8db9e7 | 118 | if (_victory_check==true){ |
shahidsajid | 30:43aace0fdbdf | 119 | _ux.victory_menu(lcd); |
shahidsajid | 26:6427f09cf8d3 | 120 | _new_game=1; |
shahidsajid | 30:43aace0fdbdf | 121 | _ball.reset_ball_count(); |
shahidsajid | 18:a260ce8db9e7 | 122 | } |
shahidsajid | 18:a260ce8db9e7 | 123 | } |
shahidsajid | 12:954da4f4e565 | 124 | void Cricket::init_positions(){ |
shahidsajid | 20:9d21599fe350 | 125 | set_init_positions(42,15,N,1); |
shahidsajid | 15:81a3aaf52647 | 126 | set_init_positions(84,30,E,2); |
shahidsajid | 15:81a3aaf52647 | 127 | set_init_positions(0,30,W,3); |
shahidsajid | 15:81a3aaf52647 | 128 | set_init_positions(2,44,SW,4); |
shahidsajid | 15:81a3aaf52647 | 129 | set_init_positions(0,2,NW,5); |
shahidsajid | 20:9d21599fe350 | 130 | set_init_positions(65,2,NE,6); |
shahidsajid | 15:81a3aaf52647 | 131 | set_init_positions(60,44,SE,7); |
shahidsajid | 12:954da4f4e565 | 132 | } |
shahidsajid | 21:a0904159e183 | 133 | |
shahidsajid | 12:954da4f4e565 | 134 | void Cricket::set_init_positions(int x,int y, Direction direction,int no){ |
shahidsajid | 26:6427f09cf8d3 | 135 | positions[_init_field_counter].x=x; |
shahidsajid | 26:6427f09cf8d3 | 136 | positions[_init_field_counter].y=y; |
shahidsajid | 26:6427f09cf8d3 | 137 | positions[_init_field_counter].dir=direction; |
shahidsajid | 26:6427f09cf8d3 | 138 | positions[_init_field_counter].no=no; |
shahidsajid | 26:6427f09cf8d3 | 139 | _init_field_counter++; |
shahidsajid | 12:954da4f4e565 | 140 | } |
shahidsajid | 11:f481ec642cc5 | 141 | void Cricket::play_game(N5110 &lcd,Gamepad &pad){ |
shahidsajid | 30:43aace0fdbdf | 142 | _check_hit=_bat.get_hitBall(_ux); |
shahidsajid | 26:6427f09cf8d3 | 143 | if (_check_hit==1){ |
shahidsajid | 26:6427f09cf8d3 | 144 | _set_hit=1; |
shahidsajid | 21:a0904159e183 | 145 | } |
shahidsajid | 30:43aace0fdbdf | 146 | _loft_check=_bat.get_loft_ball(_ux); |
shahidsajid | 26:6427f09cf8d3 | 147 | if (_loft_check==1){ |
shahidsajid | 26:6427f09cf8d3 | 148 | _set_loft=1; |
shahidsajid | 24:23fd6b451db7 | 149 | } |
shahidsajid | 12:954da4f4e565 | 150 | Direction dir=pad.get_direction(); |
shahidsajid | 26:6427f09cf8d3 | 151 | if (_check_bowled!=1){ |
shahidsajid | 30:43aace0fdbdf | 152 | _check_bowled=_ball.ball_start(pad); |
shahidsajid | 12:954da4f4e565 | 153 | } |
shahidsajid | 12:954da4f4e565 | 154 | else{ |
shahidsajid | 26:6427f09cf8d3 | 155 | update_game(_set_hit, _set_loft, dir,pad,lcd); |
shahidsajid | 12:954da4f4e565 | 156 | } |
shahidsajid | 11:f481ec642cc5 | 157 | } |
shahidsajid | 30:43aace0fdbdf | 158 | void Cricket::update_game(int checkHit,int _loft_check, Direction dir,Gamepad &pad,N5110 &lcd){ |
shahidsajid | 30:43aace0fdbdf | 159 | set_ball_direction(dir); |
shahidsajid | 30:43aace0fdbdf | 160 | int fielder_check=check_fielder(ball_direction); |
shahidsajid | 15:81a3aaf52647 | 161 | if (checkHit!=1) |
shahidsajid | 21:a0904159e183 | 162 | batsman_out(2,pad,lcd); |
shahidsajid | 30:43aace0fdbdf | 163 | if(direction_set==1 && checkHit==1){ |
shahidsajid | 13:924891519a95 | 164 | if (fielder_check!=-1){ |
shahidsajid | 30:43aace0fdbdf | 165 | int _check_update=_ball.update_ball(field[fielder_check].x,field[fielder_check].y); |
shahidsajid | 30:43aace0fdbdf | 166 | printf("Location x %i y %i\n",field[fielder_check].x,field[fielder_check].y); |
shahidsajid | 30:43aace0fdbdf | 167 | if (_loft_check==1){ |
shahidsajid | 26:6427f09cf8d3 | 168 | if (_check_update==1) |
shahidsajid | 19:e1ded5acb64a | 169 | batsman_out(3,pad,lcd); |
shahidsajid | 13:924891519a95 | 170 | } |
shahidsajid | 15:81a3aaf52647 | 171 | else |
shahidsajid | 30:43aace0fdbdf | 172 | update_scoreboard(_check_update,field[fielder_check].position+1,pad); |
shahidsajid | 13:924891519a95 | 173 | } |
shahidsajid | 13:924891519a95 | 174 | if (fielder_check==-1){ |
shahidsajid | 30:43aace0fdbdf | 175 | _check_update=_ball.update_ball(positions[_position_no].x,positions[_position_no].y); |
shahidsajid | 26:6427f09cf8d3 | 176 | printf("location x %i y %i\n update %i\n",positions[_position_no].x,positions[_position_no].y,_check_update); |
shahidsajid | 30:43aace0fdbdf | 177 | if (_loft_check==1) |
shahidsajid | 26:6427f09cf8d3 | 178 | update_scoreboard(_check_update,6,pad); |
shahidsajid | 15:81a3aaf52647 | 179 | else |
shahidsajid | 30:43aace0fdbdf | 180 | update_scoreboard(_check_update,4,pad); |
shahidsajid | 13:924891519a95 | 181 | } |
shahidsajid | 15:81a3aaf52647 | 182 | } |
shahidsajid | 30:43aace0fdbdf | 183 | } |
shahidsajid | 15:81a3aaf52647 | 184 | void Cricket::update_scoreboard(int checkUpdate, int runs,Gamepad &pad){ |
shahidsajid | 28:d0b0a64a832d | 185 | if (checkUpdate==1){ |
shahidsajid | 30:43aace0fdbdf | 186 | if (ball_direction==N){ |
shahidsajid | 30:43aace0fdbdf | 187 | _scoreboard.update_score(0); |
shahidsajid | 20:9d21599fe350 | 188 | pad.led(3,1.0); |
shahidsajid | 20:9d21599fe350 | 189 | wait(0.5); |
shahidsajid | 26:6427f09cf8d3 | 190 | _new_round=1; |
shahidsajid | 20:9d21599fe350 | 191 | } |
shahidsajid | 20:9d21599fe350 | 192 | else{ |
shahidsajid | 30:43aace0fdbdf | 193 | _scoreboard.update_score(runs); |
shahidsajid | 20:9d21599fe350 | 194 | pad.led(3,1.0); |
shahidsajid | 20:9d21599fe350 | 195 | wait(0.5); |
shahidsajid | 26:6427f09cf8d3 | 196 | _new_round=1; |
shahidsajid | 30:43aace0fdbdf | 197 | } |
shahidsajid | 14:122eaa3b7a50 | 198 | } |
shahidsajid | 24:23fd6b451db7 | 199 | pad.leds_off(); |
shahidsajid | 13:924891519a95 | 200 | } |
shahidsajid | 20:9d21599fe350 | 201 | |
shahidsajid | 19:e1ded5acb64a | 202 | void Cricket::batsman_out(int option,Gamepad &pad, N5110 &lcd){ |
shahidsajid | 30:43aace0fdbdf | 203 | _scoreboard.reset(); |
shahidsajid | 15:81a3aaf52647 | 204 | pad.led(1,1.0); |
shahidsajid | 18:a260ce8db9e7 | 205 | //pad.tone(750.0,0.5); |
shahidsajid | 30:43aace0fdbdf | 206 | _ball.reset_ball_count(); |
shahidsajid | 30:43aace0fdbdf | 207 | _ux.game_over_menu(lcd,option); |
shahidsajid | 24:23fd6b451db7 | 208 | game_reset(); |
shahidsajid | 26:6427f09cf8d3 | 209 | _new_game=1; |
shahidsajid | 15:81a3aaf52647 | 210 | wait(2); |
shahidsajid | 24:23fd6b451db7 | 211 | pad.leds_off(); |
shahidsajid | 30:43aace0fdbdf | 212 | _ux.second_menu(lcd); |
shahidsajid | 30:43aace0fdbdf | 213 | } |
shahidsajid | 13:924891519a95 | 214 | void Cricket::draw(N5110 &lcd){ |
shahidsajid | 13:924891519a95 | 215 | lcd.drawCircle((WIDTH/2),HEIGHT/2,23,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 216 | lcd.drawRect(37,11,12,30,FILL_TRANSPARENT); |
shahidsajid | 30:43aace0fdbdf | 217 | _ball.draw(lcd); |
shahidsajid | 13:924891519a95 | 218 | draw_field(lcd); |
shahidsajid | 30:43aace0fdbdf | 219 | _bat.draw(lcd); |
shahidsajid | 30:43aace0fdbdf | 220 | _scoreboard.draw(lcd); |
shahidsajid | 13:924891519a95 | 221 | } |
shahidsajid | 13:924891519a95 | 222 | void Cricket::set_ball_direction(Direction dir){ |
shahidsajid | 30:43aace0fdbdf | 223 | if (direction_set!=1){ |
shahidsajid | 26:6427f09cf8d3 | 224 | for (int i=0;i<_init_field_counter+1;i++){ |
shahidsajid | 20:9d21599fe350 | 225 | if(dir==positions[i].dir){ |
shahidsajid | 30:43aace0fdbdf | 226 | ball_direction=dir; |
shahidsajid | 20:9d21599fe350 | 227 | printf(" BALL DIRECTION %i x %i y %i \n",positions[i].no,positions[i].x,positions[i].y); |
shahidsajid | 20:9d21599fe350 | 228 | _position_no=i; |
shahidsajid | 30:43aace0fdbdf | 229 | direction_set=1; |
shahidsajid | 30:43aace0fdbdf | 230 | break; |
shahidsajid | 20:9d21599fe350 | 231 | } |
shahidsajid | 20:9d21599fe350 | 232 | } |
shahidsajid | 12:954da4f4e565 | 233 | } |
shahidsajid | 12:954da4f4e565 | 234 | } |
shahidsajid | 13:924891519a95 | 235 | int Cricket::check_fielder(Direction dir){ |
shahidsajid | 30:43aace0fdbdf | 236 | Vector2D p; |
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 | 30:43aace0fdbdf | 262 | pos=rand()%2; |
shahidsajid | 10:6c6e09023942 | 263 | for (int j=0;j<10;j++){ |
shahidsajid | 30:43aace0fdbdf | 264 | if (fieldNumbers[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 | 30:43aace0fdbdf | 278 | fieldNumbers[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 | 30:43aace0fdbdf | 287 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 288 | i++; |
shahidsajid | 26:6427f09cf8d3 | 289 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 290 | } |
shahidsajid | 10:6c6e09023942 | 291 | } |
shahidsajid | 30:43aace0fdbdf | 292 | |
shahidsajid | 30:43aace0fdbdf | 293 | |
shahidsajid | 10:6c6e09023942 | 294 | if (d==2){ //NE |
shahidsajid | 10:6c6e09023942 | 295 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 296 | field[i].dir=NE; |
shahidsajid | 10:6c6e09023942 | 297 | field[i].x=55; |
shahidsajid | 10:6c6e09023942 | 298 | field[i].y=9; |
shahidsajid | 10:6c6e09023942 | 299 | field[i].position=1; |
shahidsajid | 30:43aace0fdbdf | 300 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 301 | i++; |
shahidsajid | 26:6427f09cf8d3 | 302 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 303 | } |
shahidsajid | 10:6c6e09023942 | 304 | else{ |
shahidsajid | 10:6c6e09023942 | 305 | field[i].dir=NE; |
shahidsajid | 10:6c6e09023942 | 306 | field[i].x=65; |
shahidsajid | 10:6c6e09023942 | 307 | field[i].y=2; |
shahidsajid | 10:6c6e09023942 | 308 | field[i].position=0; |
shahidsajid | 30:43aace0fdbdf | 309 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 310 | i++; |
shahidsajid | 26:6427f09cf8d3 | 311 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 312 | } |
shahidsajid | 10:6c6e09023942 | 313 | } |
shahidsajid | 30:43aace0fdbdf | 314 | |
shahidsajid | 30:43aace0fdbdf | 315 | |
shahidsajid | 10:6c6e09023942 | 316 | if (d==3){ //SW |
shahidsajid | 10:6c6e09023942 | 317 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 318 | field[i].dir=SW; |
shahidsajid | 10:6c6e09023942 | 319 | field[i].x=33; |
shahidsajid | 10:6c6e09023942 | 320 | field[i].y=40; |
shahidsajid | 10:6c6e09023942 | 321 | field[i].position=1; |
shahidsajid | 30:43aace0fdbdf | 322 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 323 | i++; |
shahidsajid | 26:6427f09cf8d3 | 324 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 325 | } |
shahidsajid | 30:43aace0fdbdf | 326 | |
shahidsajid | 10:6c6e09023942 | 327 | else{ |
shahidsajid | 10:6c6e09023942 | 328 | field[i].dir=SW; |
shahidsajid | 10:6c6e09023942 | 329 | field[i].x=25; |
shahidsajid | 10:6c6e09023942 | 330 | field[i].y=44; |
shahidsajid | 10:6c6e09023942 | 331 | field[i].position=0; |
shahidsajid | 30:43aace0fdbdf | 332 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 333 | i++; |
shahidsajid | 26:6427f09cf8d3 | 334 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 335 | } |
shahidsajid | 10:6c6e09023942 | 336 | } |
shahidsajid | 30:43aace0fdbdf | 337 | |
shahidsajid | 10:6c6e09023942 | 338 | if (d==4){ //SE |
shahidsajid | 10:6c6e09023942 | 339 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 340 | field[i].dir=SE; |
shahidsajid | 10:6c6e09023942 | 341 | field[i].x=55; |
shahidsajid | 10:6c6e09023942 | 342 | field[i].y=40; |
shahidsajid | 10:6c6e09023942 | 343 | field[i].position=1; |
shahidsajid | 30:43aace0fdbdf | 344 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 345 | i++; |
shahidsajid | 26:6427f09cf8d3 | 346 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 347 | } |
shahidsajid | 10:6c6e09023942 | 348 | else{ |
shahidsajid | 10:6c6e09023942 | 349 | field[i].dir=SE; |
shahidsajid | 10:6c6e09023942 | 350 | field[i].x=65; |
shahidsajid | 10:6c6e09023942 | 351 | field[i].y=44; |
shahidsajid | 10:6c6e09023942 | 352 | field[i].position=0; |
shahidsajid | 30:43aace0fdbdf | 353 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 354 | i++; |
shahidsajid | 26:6427f09cf8d3 | 355 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 356 | } |
shahidsajid | 10:6c6e09023942 | 357 | } |
shahidsajid | 30:43aace0fdbdf | 358 | |
shahidsajid | 10:6c6e09023942 | 359 | if (d==5){ //W |
shahidsajid | 10:6c6e09023942 | 360 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 361 | field[i].dir=W; |
shahidsajid | 10:6c6e09023942 | 362 | field[i].x=3; |
shahidsajid | 15:81a3aaf52647 | 363 | field[i].y=30; |
shahidsajid | 10:6c6e09023942 | 364 | field[i].position=1; |
shahidsajid | 30:43aace0fdbdf | 365 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 366 | i++; |
shahidsajid | 26:6427f09cf8d3 | 367 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 368 | } |
shahidsajid | 10:6c6e09023942 | 369 | else{ |
shahidsajid | 10:6c6e09023942 | 370 | field[i].dir=W; |
shahidsajid | 10:6c6e09023942 | 371 | field[i].x=25; |
shahidsajid | 15:81a3aaf52647 | 372 | field[i].y=30; |
shahidsajid | 10:6c6e09023942 | 373 | field[i].position=0; |
shahidsajid | 30:43aace0fdbdf | 374 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 375 | i++; |
shahidsajid | 26:6427f09cf8d3 | 376 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 377 | } |
shahidsajid | 30:43aace0fdbdf | 378 | } |
shahidsajid | 10:6c6e09023942 | 379 | if (d==6){ //W |
shahidsajid | 10:6c6e09023942 | 380 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 381 | field[i].dir=E; |
shahidsajid | 10:6c6e09023942 | 382 | field[i].x=80; |
shahidsajid | 15:81a3aaf52647 | 383 | field[i].y=30; |
shahidsajid | 10:6c6e09023942 | 384 | field[i].position=1; |
shahidsajid | 30:43aace0fdbdf | 385 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 386 | i++; |
shahidsajid | 26:6427f09cf8d3 | 387 | _fielders_count++; |
shahidsajid | 10:6c6e09023942 | 388 | } |
shahidsajid | 10:6c6e09023942 | 389 | else{ |
shahidsajid | 10:6c6e09023942 | 390 | field[i].dir=E; |
shahidsajid | 15:81a3aaf52647 | 391 | field[i].x=60; |
shahidsajid | 15:81a3aaf52647 | 392 | field[i].y=30; |
shahidsajid | 15:81a3aaf52647 | 393 | field[i].position=0; |
shahidsajid | 30:43aace0fdbdf | 394 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 395 | i++; |
shahidsajid | 26:6427f09cf8d3 | 396 | _fielders_count++; |
shahidsajid | 30:43aace0fdbdf | 397 | } |
shahidsajid | 10:6c6e09023942 | 398 | } |
shahidsajid | 10:6c6e09023942 | 399 | } |
shahidsajid | 24:23fd6b451db7 | 400 | } |
shahidsajid | 24:23fd6b451db7 | 401 | void Cricket::info_screen(N5110 &lcd,int target){ |
shahidsajid | 24:23fd6b451db7 | 402 | lcd.clear(); |
shahidsajid | 30:43aace0fdbdf | 403 | lcd.printString("YOU ARE GIVEN",2,1); |
shahidsajid | 30:43aace0fdbdf | 404 | lcd.printString("10 BALLS ",3,2); |
shahidsajid | 24:23fd6b451db7 | 405 | lcd.refresh(); |
shahidsajid | 24:23fd6b451db7 | 406 | wait(0.5); |
shahidsajid | 24:23fd6b451db7 | 407 | char buffer[5]; |
shahidsajid | 24:23fd6b451db7 | 408 | int length=sprintf(buffer,"SCORE %i RUNS",target); |
shahidsajid | 24:23fd6b451db7 | 409 | lcd.printString(buffer,2,4); |
shahidsajid | 24:23fd6b451db7 | 410 | lcd.refresh(); |
shahidsajid | 24:23fd6b451db7 | 411 | wait(0.5); |
shahidsajid | 24:23fd6b451db7 | 412 | lcd.printString("GOOD LUCK!!!",0,5); |
shahidsajid | 24:23fd6b451db7 | 413 | lcd.refresh(); |
shahidsajid | 24:23fd6b451db7 | 414 | wait(3); |
shahidsajid | 24:23fd6b451db7 | 415 | } |