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@20:9d21599fe350, 2019-04-30 (annotated)
- Committer:
- shahidsajid
- Date:
- Tue Apr 30 10:27:23 2019 +0000
- Revision:
- 20:9d21599fe350
- Parent:
- 19:e1ded5acb64a
- Child:
- 21:a0904159e183
Created starting menus with correct button functionality;
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 | 10:6c6e09023942 | 16 | bat.init(4,5); |
shahidsajid | 10:6c6e09023942 | 17 | ball.init(2,3); |
shahidsajid | 14:122eaa3b7a50 | 18 | scoreboard.init(); |
shahidsajid | 12:954da4f4e565 | 19 | //float f; |
shahidsajid | 14:122eaa3b7a50 | 20 | new_round=1; |
shahidsajid | 12:954da4f4e565 | 21 | direction_set=0; |
shahidsajid | 18:a260ce8db9e7 | 22 | new_game=1; |
shahidsajid | 12:954da4f4e565 | 23 | fieldersCount=0; |
shahidsajid | 12:954da4f4e565 | 24 | init_field_counter=0; |
shahidsajid | 12:954da4f4e565 | 25 | init_positions(); |
shahidsajid | 20:9d21599fe350 | 26 | _position_no=-1; |
shahidsajid | 12:954da4f4e565 | 27 | check_bowled=0; |
shahidsajid | 18:a260ce8db9e7 | 28 | _ball_limit=3; |
shahidsajid | 15:81a3aaf52647 | 29 | check_hit=0; |
shahidsajid | 15:81a3aaf52647 | 30 | loft_check=0; |
shahidsajid | 13:924891519a95 | 31 | outfield_fielder=-1; |
shahidsajid | 15:81a3aaf52647 | 32 | check_update=-1; |
shahidsajid | 13:924891519a95 | 33 | } |
shahidsajid | 19:e1ded5acb64a | 34 | void Cricket::round_reset(){ |
shahidsajid | 14:122eaa3b7a50 | 35 | ball.reset(); |
shahidsajid | 14:122eaa3b7a50 | 36 | bat.reset(); |
shahidsajid | 14:122eaa3b7a50 | 37 | new_round=0; |
shahidsajid | 13:924891519a95 | 38 | direction_set=0; |
shahidsajid | 13:924891519a95 | 39 | fieldersCount=0; |
shahidsajid | 15:81a3aaf52647 | 40 | loft_check=0; |
shahidsajid | 15:81a3aaf52647 | 41 | check_hit=0; |
shahidsajid | 15:81a3aaf52647 | 42 | ballHit=0; |
shahidsajid | 13:924891519a95 | 43 | init_field_counter=0; |
shahidsajid | 13:924891519a95 | 44 | init_positions(); |
shahidsajid | 20:9d21599fe350 | 45 | _position_no=-1; |
shahidsajid | 13:924891519a95 | 46 | check_bowled=0; |
shahidsajid | 14:122eaa3b7a50 | 47 | outfield_fielder=-1; |
shahidsajid | 15:81a3aaf52647 | 48 | check_update=-1; |
shahidsajid | 19:e1ded5acb64a | 49 | } |
shahidsajid | 19:e1ded5acb64a | 50 | void Cricket::game_reset(){ |
shahidsajid | 19:e1ded5acb64a | 51 | round_reset(); |
shahidsajid | 19:e1ded5acb64a | 52 | new_game=1; |
shahidsajid | 19:e1ded5acb64a | 53 | scoreboard.reset(); |
shahidsajid | 19:e1ded5acb64a | 54 | ball.reset_ball_count(); |
shahidsajid | 10:6c6e09023942 | 55 | } |
shahidsajid | 11:f481ec642cc5 | 56 | void Cricket::game(N5110 &lcd,Gamepad &pad){ |
shahidsajid | 20:9d21599fe350 | 57 | |
shahidsajid | 18:a260ce8db9e7 | 58 | if (new_game==1){ |
shahidsajid | 18:a260ce8db9e7 | 59 | scoreboard.generate_target(); |
shahidsajid | 20:9d21599fe350 | 60 | bat.first_menu(lcd,pad); |
shahidsajid | 20:9d21599fe350 | 61 | //bat.info_screen(lcd,scoreboard.get_target()); |
shahidsajid | 19:e1ded5acb64a | 62 | new_game=0; |
shahidsajid | 18:a260ce8db9e7 | 63 | } |
shahidsajid | 20:9d21599fe350 | 64 | |
shahidsajid | 14:122eaa3b7a50 | 65 | if (new_round==1){ |
shahidsajid | 20:9d21599fe350 | 66 | |
shahidsajid | 18:a260ce8db9e7 | 67 | if (scoreboard.compare_target()==true){ |
shahidsajid | 18:a260ce8db9e7 | 68 | bat.victory_menu(lcd); |
shahidsajid | 19:e1ded5acb64a | 69 | game_reset(); |
shahidsajid | 18:a260ce8db9e7 | 70 | } |
shahidsajid | 19:e1ded5acb64a | 71 | else if(check_ball_count(lcd)==true){ |
shahidsajid | 19:e1ded5acb64a | 72 | bat.game_over_menu(lcd,1); |
shahidsajid | 19:e1ded5acb64a | 73 | game_reset(); |
shahidsajid | 19:e1ded5acb64a | 74 | } |
shahidsajid | 19:e1ded5acb64a | 75 | else{ |
shahidsajid | 20:9d21599fe350 | 76 | |
shahidsajid | 19:e1ded5acb64a | 77 | check_ball_count(lcd); |
shahidsajid | 19:e1ded5acb64a | 78 | pad.leds_off(); |
shahidsajid | 19:e1ded5acb64a | 79 | round_reset(); |
shahidsajid | 19:e1ded5acb64a | 80 | set_field(lcd); |
shahidsajid | 19:e1ded5acb64a | 81 | ball.increment_ball_count(); |
shahidsajid | 19:e1ded5acb64a | 82 | play_game(lcd,pad); |
shahidsajid | 19:e1ded5acb64a | 83 | new_round=0; |
shahidsajid | 19:e1ded5acb64a | 84 | } |
shahidsajid | 13:924891519a95 | 85 | } |
shahidsajid | 13:924891519a95 | 86 | else |
shahidsajid | 13:924891519a95 | 87 | play_game(lcd,pad); |
shahidsajid | 20:9d21599fe350 | 88 | |
shahidsajid | 10:6c6e09023942 | 89 | } |
shahidsajid | 19:e1ded5acb64a | 90 | bool Cricket::check_ball_count(N5110 &lcd){ |
shahidsajid | 18:a260ce8db9e7 | 91 | int count=ball.get_ball_count(); |
shahidsajid | 18:a260ce8db9e7 | 92 | if (count==_ball_limit){ |
shahidsajid | 18:a260ce8db9e7 | 93 | new_round=1; |
shahidsajid | 18:a260ce8db9e7 | 94 | ball.reset_ball_count(); |
shahidsajid | 18:a260ce8db9e7 | 95 | new_game=1; |
shahidsajid | 19:e1ded5acb64a | 96 | return true; |
shahidsajid | 19:e1ded5acb64a | 97 | } |
shahidsajid | 19:e1ded5acb64a | 98 | else{ |
shahidsajid | 19:e1ded5acb64a | 99 | return false; |
shahidsajid | 18:a260ce8db9e7 | 100 | } |
shahidsajid | 18:a260ce8db9e7 | 101 | } |
shahidsajid | 18:a260ce8db9e7 | 102 | void Cricket::check_victory(N5110 &lcd){ |
shahidsajid | 18:a260ce8db9e7 | 103 | bool _victory_check=scoreboard.compare_target(); |
shahidsajid | 18:a260ce8db9e7 | 104 | if (_victory_check==true){ |
shahidsajid | 18:a260ce8db9e7 | 105 | bat.victory_menu(lcd); |
shahidsajid | 18:a260ce8db9e7 | 106 | new_game=1; |
shahidsajid | 18:a260ce8db9e7 | 107 | ball.reset_ball_count(); |
shahidsajid | 18:a260ce8db9e7 | 108 | } |
shahidsajid | 18:a260ce8db9e7 | 109 | } |
shahidsajid | 12:954da4f4e565 | 110 | void Cricket::init_positions(){ |
shahidsajid | 20:9d21599fe350 | 111 | set_init_positions(42,15,N,1); |
shahidsajid | 15:81a3aaf52647 | 112 | set_init_positions(84,30,E,2); |
shahidsajid | 15:81a3aaf52647 | 113 | set_init_positions(0,30,W,3); |
shahidsajid | 15:81a3aaf52647 | 114 | set_init_positions(2,44,SW,4); |
shahidsajid | 15:81a3aaf52647 | 115 | set_init_positions(0,2,NW,5); |
shahidsajid | 20:9d21599fe350 | 116 | set_init_positions(65,2,NE,6); |
shahidsajid | 15:81a3aaf52647 | 117 | set_init_positions(60,44,SE,7); |
shahidsajid | 12:954da4f4e565 | 118 | } |
shahidsajid | 12:954da4f4e565 | 119 | void Cricket::set_init_positions(int x,int y, Direction direction,int no){ |
shahidsajid | 12:954da4f4e565 | 120 | positions[init_field_counter].x=x; |
shahidsajid | 12:954da4f4e565 | 121 | positions[init_field_counter].y=y; |
shahidsajid | 12:954da4f4e565 | 122 | positions[init_field_counter].dir=direction; |
shahidsajid | 12:954da4f4e565 | 123 | positions[init_field_counter].no=no; |
shahidsajid | 12:954da4f4e565 | 124 | init_field_counter++; |
shahidsajid | 12:954da4f4e565 | 125 | } |
shahidsajid | 11:f481ec642cc5 | 126 | void Cricket::play_game(N5110 &lcd,Gamepad &pad){ |
shahidsajid | 15:81a3aaf52647 | 127 | check_hit=bat.get_hitBall(); |
shahidsajid | 15:81a3aaf52647 | 128 | loft_check=bat.get_loft_ball(); |
shahidsajid | 12:954da4f4e565 | 129 | Direction dir=pad.get_direction(); |
shahidsajid | 12:954da4f4e565 | 130 | if (check_bowled!=1){ |
shahidsajid | 15:81a3aaf52647 | 131 | check_bowled=ball.ball_start(pad); |
shahidsajid | 12:954da4f4e565 | 132 | } |
shahidsajid | 12:954da4f4e565 | 133 | else{ |
shahidsajid | 19:e1ded5acb64a | 134 | update_game(check_hit, loft_check, dir,pad,lcd); |
shahidsajid | 12:954da4f4e565 | 135 | } |
shahidsajid | 11:f481ec642cc5 | 136 | } |
shahidsajid | 19:e1ded5acb64a | 137 | void Cricket::update_game(int checkHit,int loft_check, Direction dir,Gamepad &pad,N5110 &lcd){ |
shahidsajid | 13:924891519a95 | 138 | set_ball_direction(dir); |
shahidsajid | 13:924891519a95 | 139 | int fielder_check=check_fielder(ball_direction); |
shahidsajid | 15:81a3aaf52647 | 140 | if (checkHit!=1) |
shahidsajid | 19:e1ded5acb64a | 141 | batsman_out(1,pad,lcd); |
shahidsajid | 15:81a3aaf52647 | 142 | if(direction_set==1 && checkHit==1){ |
shahidsajid | 13:924891519a95 | 143 | if (fielder_check!=-1){ |
shahidsajid | 15:81a3aaf52647 | 144 | int check_update=ball.update_ball(field[fielder_check].x,field[fielder_check].y); |
shahidsajid | 15:81a3aaf52647 | 145 | printf("Location x %i y %i\n",field[fielder_check].x,field[fielder_check].y); |
shahidsajid | 15:81a3aaf52647 | 146 | if (loft_check==1){ |
shahidsajid | 15:81a3aaf52647 | 147 | if (check_update==1) |
shahidsajid | 19:e1ded5acb64a | 148 | batsman_out(3,pad,lcd); |
shahidsajid | 13:924891519a95 | 149 | } |
shahidsajid | 15:81a3aaf52647 | 150 | else |
shahidsajid | 15:81a3aaf52647 | 151 | update_scoreboard(check_update,field[fielder_check].position+1,pad); |
shahidsajid | 13:924891519a95 | 152 | } |
shahidsajid | 13:924891519a95 | 153 | if (fielder_check==-1){ |
shahidsajid | 20:9d21599fe350 | 154 | check_update=ball.update_ball(positions[_position_no].x,positions[_position_no].y); |
shahidsajid | 20:9d21599fe350 | 155 | printf("location x %i y %i\n update %i\n",positions[_position_no].x,positions[_position_no].y,check_update); |
shahidsajid | 15:81a3aaf52647 | 156 | if (loft_check==1) |
shahidsajid | 15:81a3aaf52647 | 157 | update_scoreboard(check_update,6,pad); |
shahidsajid | 15:81a3aaf52647 | 158 | else |
shahidsajid | 15:81a3aaf52647 | 159 | update_scoreboard(check_update,4,pad); |
shahidsajid | 13:924891519a95 | 160 | } |
shahidsajid | 15:81a3aaf52647 | 161 | } |
shahidsajid | 15:81a3aaf52647 | 162 | } |
shahidsajid | 15:81a3aaf52647 | 163 | void Cricket::update_scoreboard(int checkUpdate, int runs,Gamepad &pad){ |
shahidsajid | 15:81a3aaf52647 | 164 | if (checkUpdate==1){ |
shahidsajid | 20:9d21599fe350 | 165 | if (ball_direction==N){ |
shahidsajid | 20:9d21599fe350 | 166 | scoreboard.update_score(0); |
shahidsajid | 20:9d21599fe350 | 167 | pad.led(3,1.0); |
shahidsajid | 20:9d21599fe350 | 168 | wait(0.5); |
shahidsajid | 20:9d21599fe350 | 169 | new_round=1; |
shahidsajid | 20:9d21599fe350 | 170 | } |
shahidsajid | 20:9d21599fe350 | 171 | else{ |
shahidsajid | 20:9d21599fe350 | 172 | scoreboard.update_score(runs); |
shahidsajid | 20:9d21599fe350 | 173 | pad.led(3,1.0); |
shahidsajid | 20:9d21599fe350 | 174 | wait(0.5); |
shahidsajid | 20:9d21599fe350 | 175 | new_round=1; |
shahidsajid | 20:9d21599fe350 | 176 | } |
shahidsajid | 14:122eaa3b7a50 | 177 | } |
shahidsajid | 13:924891519a95 | 178 | } |
shahidsajid | 20:9d21599fe350 | 179 | |
shahidsajid | 19:e1ded5acb64a | 180 | void Cricket::batsman_out(int option,Gamepad &pad, N5110 &lcd){ |
shahidsajid | 15:81a3aaf52647 | 181 | scoreboard.reset(); |
shahidsajid | 15:81a3aaf52647 | 182 | pad.led(1,1.0); |
shahidsajid | 18:a260ce8db9e7 | 183 | //pad.tone(750.0,0.5); |
shahidsajid | 19:e1ded5acb64a | 184 | ball.reset_ball_count(); |
shahidsajid | 19:e1ded5acb64a | 185 | bat.game_over_menu(lcd,option); |
shahidsajid | 19:e1ded5acb64a | 186 | new_round=1; |
shahidsajid | 15:81a3aaf52647 | 187 | wait(2); |
shahidsajid | 15:81a3aaf52647 | 188 | } |
shahidsajid | 13:924891519a95 | 189 | void Cricket::draw(N5110 &lcd){ |
shahidsajid | 13:924891519a95 | 190 | lcd.drawCircle((WIDTH/2),HEIGHT/2,23,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 191 | lcd.drawRect(37,11,12,30,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 192 | ball.draw(lcd); |
shahidsajid | 13:924891519a95 | 193 | draw_field(lcd); |
shahidsajid | 13:924891519a95 | 194 | bat.draw(lcd); |
shahidsajid | 14:122eaa3b7a50 | 195 | scoreboard.draw(lcd); |
shahidsajid | 13:924891519a95 | 196 | } |
shahidsajid | 13:924891519a95 | 197 | void Cricket::set_ball_direction(Direction dir){ |
shahidsajid | 13:924891519a95 | 198 | if (direction_set!=1){ |
shahidsajid | 20:9d21599fe350 | 199 | for (int i=0;i<init_field_counter+1;i++){ |
shahidsajid | 20:9d21599fe350 | 200 | if(dir==positions[i].dir){ |
shahidsajid | 20:9d21599fe350 | 201 | ball_direction=dir; |
shahidsajid | 20:9d21599fe350 | 202 | printf(" BALL DIRECTION %i x %i y %i \n",positions[i].no,positions[i].x,positions[i].y); |
shahidsajid | 20:9d21599fe350 | 203 | _position_no=i; |
shahidsajid | 20:9d21599fe350 | 204 | direction_set=1; |
shahidsajid | 20:9d21599fe350 | 205 | break; |
shahidsajid | 20:9d21599fe350 | 206 | } |
shahidsajid | 20:9d21599fe350 | 207 | } |
shahidsajid | 12:954da4f4e565 | 208 | } |
shahidsajid | 12:954da4f4e565 | 209 | } |
shahidsajid | 13:924891519a95 | 210 | int Cricket::check_fielder(Direction dir){ |
shahidsajid | 13:924891519a95 | 211 | Vector2D p; |
shahidsajid | 20:9d21599fe350 | 212 | if (dir==N){ |
shahidsajid | 20:9d21599fe350 | 213 | return -1; |
shahidsajid | 20:9d21599fe350 | 214 | } |
shahidsajid | 15:81a3aaf52647 | 215 | for (int i=0;i<8;i++){ |
shahidsajid | 13:924891519a95 | 216 | if(dir == field[i].dir){ |
shahidsajid | 13:924891519a95 | 217 | return i; |
shahidsajid | 13:924891519a95 | 218 | } |
shahidsajid | 13:924891519a95 | 219 | } |
shahidsajid | 13:924891519a95 | 220 | return -1; |
shahidsajid | 10:6c6e09023942 | 221 | } |
shahidsajid | 10:6c6e09023942 | 222 | void Cricket::draw_field(N5110 &lcd){ |
shahidsajid | 13:924891519a95 | 223 | lcd.drawCircle(field[0].x,field[0].y,2,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 224 | lcd.drawCircle(field[1].x,field[1].y,2,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 225 | lcd.drawCircle(field[2].x,field[2].y,2,FILL_TRANSPARENT); |
shahidsajid | 13:924891519a95 | 226 | lcd.drawCircle(field[3].x,field[3].y,2,FILL_TRANSPARENT); |
shahidsajid | 14:122eaa3b7a50 | 227 | lcd.drawCircle(field[4].x,field[4].y,2,FILL_TRANSPARENT); |
shahidsajid | 10:6c6e09023942 | 228 | } |
shahidsajid | 10:6c6e09023942 | 229 | void Cricket::set_field(N5110 &lcd){ |
shahidsajid | 10:6c6e09023942 | 230 | int d=0; |
shahidsajid | 10:6c6e09023942 | 231 | int pos=0; |
shahidsajid | 10:6c6e09023942 | 232 | int i=0; |
shahidsajid | 10:6c6e09023942 | 233 | int continueCount=0; |
shahidsajid | 10:6c6e09023942 | 234 | srand(time(NULL)); |
shahidsajid | 10:6c6e09023942 | 235 | while (fieldersCount!=5){ |
shahidsajid | 10:6c6e09023942 | 236 | d = 1+ rand() % 6; |
shahidsajid | 10:6c6e09023942 | 237 | pos=rand()%2; |
shahidsajid | 10:6c6e09023942 | 238 | for (int j=0;j<10;j++){ |
shahidsajid | 10:6c6e09023942 | 239 | if (fieldNumbers[j]==d){ |
shahidsajid | 10:6c6e09023942 | 240 | continueCount=1; |
shahidsajid | 10:6c6e09023942 | 241 | } |
shahidsajid | 10:6c6e09023942 | 242 | } |
shahidsajid | 10:6c6e09023942 | 243 | if (continueCount==1){ |
shahidsajid | 10:6c6e09023942 | 244 | continueCount=0; |
shahidsajid | 10:6c6e09023942 | 245 | continue; |
shahidsajid | 10:6c6e09023942 | 246 | } |
shahidsajid | 10:6c6e09023942 | 247 | if (d==1){ //NW |
shahidsajid | 10:6c6e09023942 | 248 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 249 | field[i].dir=NW; |
shahidsajid | 10:6c6e09023942 | 250 | field[i].x=30; |
shahidsajid | 10:6c6e09023942 | 251 | field[i].y=9; |
shahidsajid | 10:6c6e09023942 | 252 | field[i].position=1; |
shahidsajid | 10:6c6e09023942 | 253 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 254 | i++; |
shahidsajid | 10:6c6e09023942 | 255 | fieldersCount++; |
shahidsajid | 10:6c6e09023942 | 256 | } |
shahidsajid | 10:6c6e09023942 | 257 | else{ |
shahidsajid | 10:6c6e09023942 | 258 | field[i].dir=NW; |
shahidsajid | 10:6c6e09023942 | 259 | field[i].x=25; |
shahidsajid | 10:6c6e09023942 | 260 | field[i].y=2; |
shahidsajid | 10:6c6e09023942 | 261 | field[i].position=0; |
shahidsajid | 10:6c6e09023942 | 262 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 263 | i++; |
shahidsajid | 10:6c6e09023942 | 264 | fieldersCount++; |
shahidsajid | 10:6c6e09023942 | 265 | } |
shahidsajid | 10:6c6e09023942 | 266 | } |
shahidsajid | 10:6c6e09023942 | 267 | |
shahidsajid | 10:6c6e09023942 | 268 | |
shahidsajid | 10:6c6e09023942 | 269 | if (d==2){ //NE |
shahidsajid | 10:6c6e09023942 | 270 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 271 | field[i].dir=NE; |
shahidsajid | 10:6c6e09023942 | 272 | field[i].x=55; |
shahidsajid | 10:6c6e09023942 | 273 | field[i].y=9; |
shahidsajid | 10:6c6e09023942 | 274 | field[i].position=1; |
shahidsajid | 10:6c6e09023942 | 275 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 276 | i++; |
shahidsajid | 10:6c6e09023942 | 277 | fieldersCount++; |
shahidsajid | 10:6c6e09023942 | 278 | } |
shahidsajid | 10:6c6e09023942 | 279 | else{ |
shahidsajid | 10:6c6e09023942 | 280 | field[i].dir=NE; |
shahidsajid | 10:6c6e09023942 | 281 | field[i].x=65; |
shahidsajid | 10:6c6e09023942 | 282 | field[i].y=2; |
shahidsajid | 10:6c6e09023942 | 283 | field[i].position=0; |
shahidsajid | 10:6c6e09023942 | 284 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 285 | i++; |
shahidsajid | 10:6c6e09023942 | 286 | fieldersCount++; |
shahidsajid | 10:6c6e09023942 | 287 | } |
shahidsajid | 10:6c6e09023942 | 288 | } |
shahidsajid | 10:6c6e09023942 | 289 | |
shahidsajid | 10:6c6e09023942 | 290 | |
shahidsajid | 10:6c6e09023942 | 291 | if (d==3){ //SW |
shahidsajid | 10:6c6e09023942 | 292 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 293 | field[i].dir=SW; |
shahidsajid | 10:6c6e09023942 | 294 | field[i].x=33; |
shahidsajid | 10:6c6e09023942 | 295 | field[i].y=40; |
shahidsajid | 10:6c6e09023942 | 296 | field[i].position=1; |
shahidsajid | 10:6c6e09023942 | 297 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 298 | i++; |
shahidsajid | 10:6c6e09023942 | 299 | fieldersCount++; |
shahidsajid | 10:6c6e09023942 | 300 | } |
shahidsajid | 10:6c6e09023942 | 301 | |
shahidsajid | 10:6c6e09023942 | 302 | else{ |
shahidsajid | 10:6c6e09023942 | 303 | field[i].dir=SW; |
shahidsajid | 10:6c6e09023942 | 304 | field[i].x=25; |
shahidsajid | 10:6c6e09023942 | 305 | field[i].y=44; |
shahidsajid | 10:6c6e09023942 | 306 | field[i].position=0; |
shahidsajid | 10:6c6e09023942 | 307 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 308 | i++; |
shahidsajid | 10:6c6e09023942 | 309 | fieldersCount++; |
shahidsajid | 10:6c6e09023942 | 310 | } |
shahidsajid | 10:6c6e09023942 | 311 | } |
shahidsajid | 10:6c6e09023942 | 312 | |
shahidsajid | 10:6c6e09023942 | 313 | if (d==4){ //SE |
shahidsajid | 10:6c6e09023942 | 314 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 315 | field[i].dir=SE; |
shahidsajid | 10:6c6e09023942 | 316 | field[i].x=55; |
shahidsajid | 10:6c6e09023942 | 317 | field[i].y=40; |
shahidsajid | 10:6c6e09023942 | 318 | field[i].position=1; |
shahidsajid | 10:6c6e09023942 | 319 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 320 | i++; |
shahidsajid | 10:6c6e09023942 | 321 | fieldersCount++; |
shahidsajid | 10:6c6e09023942 | 322 | } |
shahidsajid | 10:6c6e09023942 | 323 | else{ |
shahidsajid | 10:6c6e09023942 | 324 | field[i].dir=SE; |
shahidsajid | 10:6c6e09023942 | 325 | field[i].x=65; |
shahidsajid | 10:6c6e09023942 | 326 | field[i].y=44; |
shahidsajid | 10:6c6e09023942 | 327 | field[i].position=0; |
shahidsajid | 10:6c6e09023942 | 328 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 329 | i++; |
shahidsajid | 10:6c6e09023942 | 330 | fieldersCount++; |
shahidsajid | 10:6c6e09023942 | 331 | } |
shahidsajid | 10:6c6e09023942 | 332 | } |
shahidsajid | 10:6c6e09023942 | 333 | |
shahidsajid | 10:6c6e09023942 | 334 | if (d==5){ //W |
shahidsajid | 10:6c6e09023942 | 335 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 336 | field[i].dir=W; |
shahidsajid | 10:6c6e09023942 | 337 | field[i].x=3; |
shahidsajid | 15:81a3aaf52647 | 338 | field[i].y=30; |
shahidsajid | 10:6c6e09023942 | 339 | field[i].position=1; |
shahidsajid | 10:6c6e09023942 | 340 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 341 | i++; |
shahidsajid | 10:6c6e09023942 | 342 | fieldersCount++; |
shahidsajid | 10:6c6e09023942 | 343 | } |
shahidsajid | 10:6c6e09023942 | 344 | else{ |
shahidsajid | 10:6c6e09023942 | 345 | field[i].dir=W; |
shahidsajid | 10:6c6e09023942 | 346 | field[i].x=25; |
shahidsajid | 15:81a3aaf52647 | 347 | field[i].y=30; |
shahidsajid | 10:6c6e09023942 | 348 | field[i].position=0; |
shahidsajid | 10:6c6e09023942 | 349 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 350 | i++; |
shahidsajid | 10:6c6e09023942 | 351 | fieldersCount++; |
shahidsajid | 10:6c6e09023942 | 352 | } |
shahidsajid | 13:924891519a95 | 353 | } |
shahidsajid | 10:6c6e09023942 | 354 | if (d==6){ //W |
shahidsajid | 10:6c6e09023942 | 355 | if (pos==1){ |
shahidsajid | 10:6c6e09023942 | 356 | field[i].dir=E; |
shahidsajid | 10:6c6e09023942 | 357 | field[i].x=80; |
shahidsajid | 15:81a3aaf52647 | 358 | field[i].y=30; |
shahidsajid | 10:6c6e09023942 | 359 | field[i].position=1; |
shahidsajid | 10:6c6e09023942 | 360 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 361 | i++; |
shahidsajid | 10:6c6e09023942 | 362 | fieldersCount++; |
shahidsajid | 10:6c6e09023942 | 363 | } |
shahidsajid | 10:6c6e09023942 | 364 | else{ |
shahidsajid | 10:6c6e09023942 | 365 | field[i].dir=E; |
shahidsajid | 15:81a3aaf52647 | 366 | field[i].x=60; |
shahidsajid | 15:81a3aaf52647 | 367 | field[i].y=30; |
shahidsajid | 15:81a3aaf52647 | 368 | field[i].position=0; |
shahidsajid | 10:6c6e09023942 | 369 | fieldNumbers[i]=d; |
shahidsajid | 10:6c6e09023942 | 370 | i++; |
shahidsajid | 10:6c6e09023942 | 371 | fieldersCount++; |
shahidsajid | 13:924891519a95 | 372 | } |
shahidsajid | 10:6c6e09023942 | 373 | } |
shahidsajid | 10:6c6e09023942 | 374 | } |
shahidsajid | 10:6c6e09023942 | 375 | |
shahidsajid | 10:6c6e09023942 | 376 | |
shahidsajid | 10:6c6e09023942 | 377 | } |