ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Revision:
24:23fd6b451db7
Parent:
21:a0904159e183
Child:
25:ead0e7bd1569
--- a/Cricket/Cricket.cpp	Tue Apr 30 13:17:14 2019 +0000
+++ b/Cricket/Cricket.cpp	Wed May 01 08:46:44 2019 +0000
@@ -24,6 +24,7 @@
    init_field_counter=0;
    init_positions();
    set_hit=0;
+   set_loft=0;
    _position_no=-1;
    check_bowled=0;
    _ball_limit=3;
@@ -42,6 +43,7 @@
    check_hit=0;
    set_hit=0;
    ballHit=0;
+   set_loft=
    init_field_counter=0;
    init_positions();
    _position_no=-1;
@@ -50,32 +52,26 @@
    check_update=-1;
 }
 void Cricket::game_reset(){
+    //pad.leds_off();
     round_reset();
     new_game=1;
     scoreboard.reset();
     ball.reset_ball_count();
 }
+void Cricket::intro(N5110 &lcd){
+    ux.first_menu(lcd);
+}
 void Cricket::game(N5110 &lcd,Gamepad &pad){
-     
      if (new_game==1){
+         printf("TEST 1\n");
          scoreboard.generate_target();
-         ux.first_menu(lcd,pad);
-         //bat.info_screen(lcd,scoreboard.get_target());
+         ux.second_menu(lcd);
          new_game=0;       
      }
-     
-     if (new_round==1){
-        
-        if (scoreboard.compare_target()==true){
-            ux.victory_menu(lcd);
+     if (new_round==1){  
+        if (game_status(lcd)==false)
             game_reset();
-        }
-        else if(check_ball_count(lcd)==true){
-           ux.game_over_menu(lcd,1);
-           game_reset();
-        }
         else{
-          
           check_ball_count(lcd);
           pad.leds_off();
           round_reset();
@@ -88,6 +84,24 @@
     else
         play_game(lcd,pad);
 }
+bool Cricket::game_status(N5110 &lcd){
+    if (scoreboard.compare_target()==true){
+             printf("COMING FROM HERE");
+             ux.victory_menu(lcd);
+             game_reset();
+             return false;
+           //}
+        }
+        else if(check_ball_count(lcd)==true){
+           ux.game_over_menu(lcd,1);
+           game_reset();
+           return false;
+        }
+        else{
+            return true;
+        }
+}
+    
 bool Cricket::check_ball_count(N5110 &lcd){
     int count=ball.get_ball_count();
     if (count==_ball_limit){
@@ -131,12 +145,15 @@
         set_hit=1;
     }
     loft_check=bat.get_loft_ball(ux);
+    if (loft_check==1){
+        set_loft=1;
+    }
     Direction dir=pad.get_direction();
     if (check_bowled!=1){
         check_bowled=ball.ball_start(pad);
     }
     else{
-        update_game(set_hit, loft_check, dir,pad,lcd);
+        update_game(set_hit, set_loft, dir,pad,lcd);
     }
 }
 void Cricket::update_game(int checkHit,int loft_check, Direction dir,Gamepad &pad,N5110 &lcd){
@@ -180,6 +197,7 @@
             new_round=1;
         }  
     }
+    pad.leds_off();
 }
 
 void Cricket::batsman_out(int option,Gamepad &pad, N5110 &lcd){
@@ -188,8 +206,10 @@
     //pad.tone(750.0,0.5);
     ball.reset_ball_count();
     ux.game_over_menu(lcd,option);
-    new_round=1;
+    game_reset();
+    new_game=1;
     wait(2);
+    pad.leds_off();
 }    
 void Cricket::draw(N5110 &lcd){
     lcd.drawCircle((WIDTH/2),HEIGHT/2,23,FILL_TRANSPARENT);
@@ -377,6 +397,21 @@
             }       
         }
   }
+}
+  void Cricket::info_screen(N5110 &lcd,int target){
+    lcd.clear();
+    lcd.printString("YOU ARE GIVEN",2,1); 
+    lcd.printString("10 BALLS ",3,2); 
+    lcd.refresh();
+    wait(0.5);
+    char buffer[5];
+    int length=sprintf(buffer,"SCORE %i RUNS",target);
+    lcd.printString(buffer,2,4);
+    lcd.refresh();
+    wait(0.5);
+    lcd.printString("GOOD LUCK!!!",0,5);
+    lcd.refresh();
+    wait(3);
+  }
   
   
-}   
\ No newline at end of file