ELEC2645 (2018/19) / Mbed 2 deprecated el17dg

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

Revision:
28:35af3843de8f
Parent:
27:f05f4e738ba9
Child:
29:579e00b7f118
--- a/game/hud.h	Mon Apr 08 14:41:57 2019 +0000
+++ b/game/hud.h	Wed Apr 10 15:42:10 2019 +0000
@@ -3,8 +3,6 @@
 
 #include "game.h"
 
-//int high_score = 0;
-
 class Hud {
 
 public:
@@ -16,20 +14,15 @@
         lcd.printString(buffer,0,0);    
     }
     
-    /*void drawHighScore(){
+    void drawHighScore(){
         if (high_score < game_score){
             high_score = game_score;
         }
-    
-    //Dysplaies the higest score reached/
-    char buffer2[32];
-    sprintf(buffer2,"High Score %i",high_score);
-    lcd.printString(buffer2,0,0);
-        
-    lcd.printString("Start Game",1,2);
-    lcd.printString("Tutorial",1,3);
-    lcd.printString("Settings",1,4);
-    }*/
+    //Displays the highest score reached.
+    char buffer[16];
+    sprintf(buffer,"High Score %i",high_score);
+    lcd.printString(buffer,0,0);
+    }
      
 /** Cheks the palyer's life value and lights the LEDs on/off accordingly to
   * how many lifes are left. 
@@ -37,35 +30,47 @@
     void displayLifes(){
         //printf("displayLifes:: %i\n", player_lifes);
         if (player_lifes == 3){
-            //turn all LEDs on
-            gamepad.leds_on();  
+            playerHasThreeLives();  
         }
         else if (player_lifes == 2){
-            // only yelow and red are lit (to tal 4)
-            
-            //gamepad.leds_on();
-            gamepad.led(6,0.0);
-            gamepad.led(3,0.0);
+            playerHasTwoLives();
         }
         else if (player_lifes == 1){
-            // red LED is lit and flashes.
-            gamepad.led(2,0.0);
-            gamepad.led(5,0.0);
-            if (red_led_flashing == 5){
-                gamepad.led(1,(float)red_led_state);
-                gamepad.led(4,(float)red_led_state);
-                gamepad.led(1,(float)!red_led_state);
-                gamepad.led(4,(float)!red_led_state);
-                red_led_flashing = 0;
-                red_led_state = !red_led_state;
-            }        
-            red_led_flashing += 1;
+            playerHasOneLife();
         }
         else {
             // all LEDs are flashing
             gamepad.leds_off();
         }        
     }
+private:
+    void playerHasThreeLives(){
+        //turn all LEDs on
+        gamepad.leds_on();
+        
+    }
+    void playerHasTwoLives(){
+      // only yelow and red are lit (total 4)
+        gamepad.led(6,0.0);
+        gamepad.led(3,0.0);
+        
+    }
+    void playerHasOneLife(){
+        // red LED is lit and flashes.
+        gamepad.led(2,0.0);
+        gamepad.led(5,0.0);
+        gamepad.led(6,0.0);
+        if (red_led_flashing == 5){
+            gamepad.led(1,(float)red_led_state);
+            gamepad.led(4,(float)red_led_state);
+            gamepad.led(1,(float)!red_led_state);
+            gamepad.led(4,(float)!red_led_state);
+            red_led_flashing = 0;
+            red_led_state = !red_led_state;
+        }        
+        red_led_flashing += 1;
+        
+    }
 };
 
 #endif
\ No newline at end of file