ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Revision:
21:a0904159e183
Parent:
20:9d21599fe350
Child:
22:69d7fe739872
Child:
24:23fd6b451db7
--- a/Cricket/Cricket.cpp	Tue Apr 30 10:27:23 2019 +0000
+++ b/Cricket/Cricket.cpp	Tue Apr 30 13:17:14 2019 +0000
@@ -13,16 +13,17 @@
 
 void Cricket::init()
 {
+   ux.init();
    bat.init(4,5);
    ball.init(2,3);
    scoreboard.init();
-   //float f;
    new_round=1;
    direction_set=0;
    new_game=1;
    fieldersCount=0;
    init_field_counter=0;
    init_positions();
+   set_hit=0;
    _position_no=-1;
    check_bowled=0;
    _ball_limit=3;
@@ -39,6 +40,7 @@
    fieldersCount=0;
    loft_check=0;
    check_hit=0;
+   set_hit=0;
    ballHit=0;
    init_field_counter=0;
    init_positions();
@@ -57,7 +59,7 @@
      
      if (new_game==1){
          scoreboard.generate_target();
-         bat.first_menu(lcd,pad);
+         ux.first_menu(lcd,pad);
          //bat.info_screen(lcd,scoreboard.get_target());
          new_game=0;       
      }
@@ -65,11 +67,11 @@
      if (new_round==1){
         
         if (scoreboard.compare_target()==true){
-            bat.victory_menu(lcd);
+            ux.victory_menu(lcd);
             game_reset();
         }
         else if(check_ball_count(lcd)==true){
-           bat.game_over_menu(lcd,1);
+           ux.game_over_menu(lcd,1);
            game_reset();
         }
         else{
@@ -85,7 +87,6 @@
     }
     else
         play_game(lcd,pad);
-    
 }
 bool Cricket::check_ball_count(N5110 &lcd){
     int count=ball.get_ball_count();
@@ -102,7 +103,7 @@
 void Cricket::check_victory(N5110 &lcd){
     bool _victory_check=scoreboard.compare_target();
         if (_victory_check==true){
-            bat.victory_menu(lcd);
+            ux.victory_menu(lcd);
             new_game=1;
             ball.reset_ball_count();
         }
@@ -116,6 +117,7 @@
     set_init_positions(65,2,NE,6);
     set_init_positions(60,44,SE,7);
 }
+
 void Cricket::set_init_positions(int x,int y, Direction direction,int no){
     positions[init_field_counter].x=x;
     positions[init_field_counter].y=y;
@@ -124,21 +126,24 @@
     init_field_counter++;
 }
 void Cricket::play_game(N5110 &lcd,Gamepad &pad){
-    check_hit=bat.get_hitBall();
-    loft_check=bat.get_loft_ball();
+    check_hit=bat.get_hitBall(ux);
+    if (check_hit==1){
+        set_hit=1;
+    }
+    loft_check=bat.get_loft_ball(ux);
     Direction dir=pad.get_direction();
     if (check_bowled!=1){
         check_bowled=ball.ball_start(pad);
     }
     else{
-        update_game(check_hit, loft_check, dir,pad,lcd);
+        update_game(set_hit, loft_check, dir,pad,lcd);
     }
 }
 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(1,pad,lcd);
+      batsman_out(2,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);
@@ -182,7 +187,7 @@
     pad.led(1,1.0);
     //pad.tone(750.0,0.5);
     ball.reset_ball_count();
-    bat.game_over_menu(lcd,option);
+    ux.game_over_menu(lcd,option);
     new_round=1;
     wait(2);
 }