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
Diff: Cricket/Cricket.cpp
- Revision:
- 19:e1ded5acb64a
- Parent:
- 18:a260ce8db9e7
- Child:
- 20:9d21599fe350
--- a/Cricket/Cricket.cpp Sat Apr 27 15:42:36 2019 +0000 +++ b/Cricket/Cricket.cpp Sat Apr 27 18:16:59 2019 +0000 @@ -31,7 +31,7 @@ outfield_fielder=-1; check_update=-1; } -void Cricket::reset(){ +void Cricket::round_reset(){ ball.reset(); bat.reset(); new_round=0; @@ -46,38 +46,53 @@ check_bowled=0; outfield_fielder=-1; check_update=-1; - +} +void Cricket::game_reset(){ + round_reset(); + new_game=1; + scoreboard.reset(); + ball.reset_ball_count(); } void Cricket::game(N5110 &lcd,Gamepad &pad){ if (new_game==1){ scoreboard.generate_target(); - new_game=0; + bat.info_screen(lcd,scoreboard.get_target()); + new_game=0; } if (new_round==1){ if (scoreboard.compare_target()==true){ bat.victory_menu(lcd); + game_reset(); } - check_ball_count(lcd); - pad.leds_off(); - reset(); - set_field(lcd); - ball.increment_ball_count(); - play_game(lcd,pad); - new_round=0; + else if(check_ball_count(lcd)==true){ + bat.game_over_menu(lcd,1); + game_reset(); + } + else{ + check_ball_count(lcd); + pad.leds_off(); + round_reset(); + set_field(lcd); + ball.increment_ball_count(); + play_game(lcd,pad); + new_round=0; + } } else { play_game(lcd,pad); - } - + } } -void Cricket::check_ball_count(N5110 &lcd){ +bool Cricket::check_ball_count(N5110 &lcd){ int count=ball.get_ball_count(); if (count==_ball_limit){ - bat.game_over_menu(lcd,1); new_round=1; ball.reset_ball_count(); new_game=1; + return true; + } + else{ + return false; } } void Cricket::check_victory(N5110 &lcd){ @@ -112,21 +127,21 @@ check_bowled=ball.ball_start(pad); } else{ - update_game(check_hit, loft_check, dir,pad); + update_game(check_hit, loft_check, dir,pad,lcd); } } -void Cricket::update_game(int checkHit,int loft_check, Direction dir,Gamepad &pad){ +void Cricket::update_game(int checkHit,int loft_check, Direction dir,Gamepad &pad,N5110 &lcd){ set_ball_direction(dir); int fielder_check=check_fielder(ball_direction); if (checkHit!=1) - batsman_out("bowled",pad); + batsman_out(1,pad,lcd); if(direction_set==1 && checkHit==1){ if (fielder_check!=-1){ int check_update=ball.update_ball(field[fielder_check].x,field[fielder_check].y); printf("Location x %i y %i\n",field[fielder_check].x,field[fielder_check].y); if (loft_check==1){ if (check_update==1) - batsman_out("Caught",pad); + batsman_out(3,pad,lcd); } else update_scoreboard(check_update,field[fielder_check].position+1,pad); @@ -152,11 +167,13 @@ new_round=1; } } -void Cricket::batsman_out(string message,Gamepad &pad){ +void Cricket::batsman_out(int option,Gamepad &pad, N5110 &lcd){ scoreboard.reset(); - new_round=1; pad.led(1,1.0); //pad.tone(750.0,0.5); + ball.reset_ball_count(); + bat.game_over_menu(lcd,option); + new_round=1; wait(2); } void Cricket::draw(N5110 &lcd){