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:
- 18:a260ce8db9e7
- Parent:
- 15:81a3aaf52647
- Child:
- 19:e1ded5acb64a
--- a/Cricket/Cricket.cpp Wed Apr 24 21:17:22 2019 +0000 +++ b/Cricket/Cricket.cpp Sat Apr 27 15:42:36 2019 +0000 @@ -19,11 +19,13 @@ //float f; new_round=1; direction_set=0; + new_game=1; fieldersCount=0; init_field_counter=0; init_positions(); fielder_no=-1; check_bowled=0; + _ball_limit=3; check_hit=0; loft_check=0; outfield_fielder=-1; @@ -47,20 +49,45 @@ } void Cricket::game(N5110 &lcd,Gamepad &pad){ + if (new_game==1){ + scoreboard.generate_target(); + new_game=0; + } if (new_round==1){ + if (scoreboard.compare_target()==true){ + bat.victory_menu(lcd); + } + check_ball_count(lcd); pad.leds_off(); 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){ + 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; + } +} +void Cricket::check_victory(N5110 &lcd){ + bool _victory_check=scoreboard.compare_target(); + if (_victory_check==true){ + bat.victory_menu(lcd); + new_game=1; + ball.reset_ball_count(); + } +} void Cricket::init_positions(){ set_init_positions(42,1,N,1); set_init_positions(84,30,E,2); @@ -129,7 +156,7 @@ scoreboard.reset(); new_round=1; pad.led(1,1.0); - pad.tone(750.0,0.5); + //pad.tone(750.0,0.5); wait(2); } void Cricket::draw(N5110 &lcd){