ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Revision:
26:6427f09cf8d3
Parent:
25:ead0e7bd1569
Child:
28:d0b0a64a832d
--- a/Cricket/Cricket.cpp	Wed May 01 09:08:03 2019 +0000
+++ b/Cricket/Cricket.cpp	Wed May 01 11:56:36 2019 +0000
@@ -17,44 +17,42 @@
    bat.init(4,5);
    ball.init(2,3);
    scoreboard.init();
-   new_round=1;
-   direction_set=0;
-   new_game=1;
-   fieldersCount=0;
-   init_field_counter=0;
+   _new_round=1;
+   _direction_set=0;
+   _new_game=1;
+   _fielders_count=0;
+   _init_field_counter=0;
    init_positions();
-   set_hit=0;
-   set_loft=0;
+   _set_hit=0;
+   _set_loft=0;
    _position_no=-1;
-   check_bowled=0;
+   _check_bowled=0;
    _ball_limit=3;
-   check_hit=0;
-   loft_check=0;
-   outfield_fielder=-1;
-   check_update=-1;
+   _check_hit=0;
+   _loft_check=0;
+   _check_update=-1;
 }
 void Cricket::round_reset(){
    ball.reset();
    bat.reset();
-   new_round=0;
-   direction_set=0;
-   fieldersCount=0;
-   loft_check=0;
-   check_hit=0;
-   set_hit=0;
+   _new_round=0;
+   _direction_set=0;
+   _fielders_count=0;
+   _loft_check=0;
+   _check_hit=0;
+   _set_hit=0;
    ballHit=0;
-   set_loft=
-   init_field_counter=0;
+   _set_loft=0;
+   _init_field_counter=0;
    init_positions();
    _position_no=-1;
-   check_bowled=0;
-   outfield_fielder=-1;
-   check_update=-1;
+   _check_bowled=0;
+   _check_update=-1;
 }
 void Cricket::game_reset(){
     //pad.leds_off();
     round_reset();
-    new_game=1;
+    _new_game=1;
     scoreboard.reset();
     ball.reset_ball_count();
 }
@@ -62,13 +60,13 @@
     ux.first_menu(lcd);
 }
 void Cricket::game(N5110 &lcd,Gamepad &pad){
-     if (new_game==1){
+     if (_new_game==1){
          printf("TEST 1\n");
          scoreboard.generate_target();
          ux.second_menu(lcd);
-         new_game=0;       
+         _new_game=0;       
      }
-     if (new_round==1){  
+     if (_new_round==1){  
         if (game_status(lcd)==false){
             game_reset();
             ux.second_menu(lcd);
@@ -80,7 +78,7 @@
           set_field(lcd);
           ball.increment_ball_count();
           play_game(lcd,pad);
-          new_round=0;
+          _new_round=0;
         }
     }
     else
@@ -107,9 +105,9 @@
 bool Cricket::check_ball_count(N5110 &lcd){
     int count=ball.get_ball_count();
     if (count==_ball_limit){
-        new_round=1;
+        _new_round=1;
         ball.reset_ball_count();
-        new_game=1;
+        _new_game=1;
         return true;
     }
     else{
@@ -120,7 +118,7 @@
     bool _victory_check=scoreboard.compare_target();
         if (_victory_check==true){
             ux.victory_menu(lcd);
-            new_game=1;
+            _new_game=1;
             ball.reset_ball_count();
         }
 }
@@ -135,68 +133,68 @@
 }
 
 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;
-    positions[init_field_counter].dir=direction;
-    positions[init_field_counter].no=no;
-    init_field_counter++;
+    positions[_init_field_counter].x=x;
+    positions[_init_field_counter].y=y;
+    positions[_init_field_counter].dir=direction;
+    positions[_init_field_counter].no=no;
+    _init_field_counter++;
 }
 void Cricket::play_game(N5110 &lcd,Gamepad &pad){
-    check_hit=bat.get_hitBall(ux);
-    if (check_hit==1){
-        set_hit=1;
+    _check_hit=bat.get_hitBall(ux);
+    if (_check_hit==1){
+        _set_hit=1;
     }
-    loft_check=bat.get_loft_ball(ux);
-    if (loft_check==1){
-        set_loft=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);
+    if (_check_bowled!=1){
+        _check_bowled=ball.ball_start(pad);
     }
     else{
-        update_game(set_hit, set_loft, 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){
   set_ball_direction(dir);
-  int fielder_check=check_fielder(ball_direction); 
+  int fielder_check=check_fielder(_ball_direction); 
   if (checkHit!=1)
       batsman_out(2,pad,lcd);
-  if(direction_set==1 && checkHit==1){
+  if(_direction_set==1 && checkHit==1){
   if (fielder_check!=-1){
-     int check_update=ball.update_ball(field[fielder_check].x,field[fielder_check].y);
+      _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)
+         if (_check_update==1)
            batsman_out(3,pad,lcd);
      }
      else
-         update_scoreboard(check_update,field[fielder_check].position+1,pad);    
+         update_scoreboard(_check_update,field[fielder_check].position+1,pad);    
   }
   if (fielder_check==-1){
-        check_update=ball.update_ball(positions[_position_no].x,positions[_position_no].y);
-        printf("location x %i y %i\n  update %i\n",positions[_position_no].x,positions[_position_no].y,check_update);
+        _check_update=ball.update_ball(positions[_position_no].x,positions[_position_no].y);
+        printf("location x %i y %i\n  update %i\n",positions[_position_no].x,positions[_position_no].y,_check_update);
         if (loft_check==1)
-         update_scoreboard(check_update,6,pad);
+         update_scoreboard(_check_update,6,pad);
         else
-            update_scoreboard(check_update,4,pad);      
+            update_scoreboard(_check_update,4,pad);      
     }
 }
 } 
 void Cricket::update_scoreboard(int checkUpdate, int runs,Gamepad &pad){
     if (checkUpdate==1){     
-        if (ball_direction==N){
+        if (_ball_direction==N){
             scoreboard.update_score(0);
             pad.led(3,1.0);
             wait(0.5);
-            new_round=1;
+            _new_round=1;
         }
         else{
             scoreboard.update_score(runs);
             pad.led(3,1.0);
             wait(0.5);
-            new_round=1;
+            _new_round=1;
         }  
     }
     pad.leds_off();
@@ -209,7 +207,7 @@
     ball.reset_ball_count();
     ux.game_over_menu(lcd,option);
     game_reset();
-    new_game=1;
+    _new_game=1;
     wait(2);
     pad.leds_off();
      ux.second_menu(lcd);
@@ -223,13 +221,13 @@
     scoreboard.draw(lcd);
 }
 void Cricket::set_ball_direction(Direction dir){
-    if (direction_set!=1){ 
-        for (int i=0;i<init_field_counter+1;i++){
+    if (_direction_set!=1){ 
+        for (int i=0;i<_init_field_counter+1;i++){
             if(dir==positions[i].dir){
-                ball_direction=dir;
+                _ball_direction=dir;
                 printf(" BALL DIRECTION %i x %i y %i \n",positions[i].no,positions[i].x,positions[i].y);
                 _position_no=i;
-                direction_set=1;
+                _direction_set=1;
                 break; 
             }
         }
@@ -260,11 +258,11 @@
     int i=0;
     int continueCount=0;
     srand(time(NULL));
-    while (fieldersCount!=5){
+    while (_fielders_count!=5){
         d = 1+ rand() % 6;
         pos=rand()%2;    
         for (int j=0;j<10;j++){
-           if (fieldNumbers[j]==d){
+           if (field_numbers[j]==d){
                 continueCount=1;
             }
         }
@@ -278,18 +276,18 @@
               field[i].x=30;
               field[i].y=9;
               field[i].position=1;
-              fieldNumbers[i]=d;
+              field_numbers[i]=d;
               i++;
-              fieldersCount++;
+              _fielders_count++;
             }
             else{
               field[i].dir=NW;
               field[i].x=25;
               field[i].y=2;
               field[i].position=0;
-              fieldNumbers[i]=d;
+              field_numbers[i]=d;
               i++;
-              fieldersCount++;
+              _fielders_count++;
             }
         }
         
@@ -300,18 +298,18 @@
             field[i].x=55;
             field[i].y=9;
             field[i].position=1;
-            fieldNumbers[i]=d;
+            field_numbers[i]=d;
               i++;
-              fieldersCount++;
+              _fielders_count++;
             }
             else{
             field[i].dir=NE;
                 field[i].x=65;
                  field[i].y=2;
                  field[i].position=0;
-                 fieldNumbers[i]=d;
+                 field_numbers[i]=d;
                   i++;
-                  fieldersCount++;
+                  _fielders_count++;
             }
         }
         
@@ -322,9 +320,9 @@
                 field[i].x=33;
                 field[i].y=40;
                 field[i].position=1;
-                fieldNumbers[i]=d;
+                field_numbers[i]=d;
                 i++;
-                fieldersCount++;
+                _fielders_count++;
             }
                 
             else{
@@ -332,9 +330,9 @@
               field[i].x=25;
               field[i].y=44;
               field[i].position=0;
-              fieldNumbers[i]=d;
+              field_numbers[i]=d;
               i++;
-              fieldersCount++;
+              _fielders_count++;
             }
         }
         
@@ -344,18 +342,18 @@
               field[i].x=55;
               field[i].y=40;
               field[i].position=1;
-              fieldNumbers[i]=d;
+              field_numbers[i]=d;
               i++;
-              fieldersCount++;
+              _fielders_count++;
             }
             else{
               field[i].dir=SE;
               field[i].x=65;
               field[i].y=44;
               field[i].position=0;
-              fieldNumbers[i]=d;
+              field_numbers[i]=d;
               i++;
-              fieldersCount++;
+              _fielders_count++;
             }
         }
         
@@ -365,18 +363,18 @@
               field[i].x=3;
               field[i].y=30;
               field[i].position=1;
-              fieldNumbers[i]=d;
+              field_numbers[i]=d;
               i++;
-              fieldersCount++;
+              _fielders_count++;
             }
             else{
               field[i].dir=W;
               field[i].x=25;
               field[i].y=30;
               field[i].position=0;
-              fieldNumbers[i]=d;
+              field_numbers[i]=d;
               i++;
-              fieldersCount++;
+              _fielders_count++;
             }
         }  
         if (d==6){ //W
@@ -385,18 +383,18 @@
                 field[i].x=80;
                 field[i].y=30;
                 field[i].position=1;
-                fieldNumbers[i]=d;
+                field_numbers[i]=d;
                 i++;
-                fieldersCount++;
+                _fielders_count++;
             }
             else{
                  field[i].dir=E;
                 field[i].x=60;
                 field[i].y=30;
                 field[i].position=0;
-                fieldNumbers[i]=d;
+                field_numbers[i]=d;
                 i++;
-                fieldersCount++;
+                _fielders_count++;
             }       
         }
   }