ELEC2645 (2017/18) / Mbed 2 deprecated fy15raf

Dependencies:   mbed

Revision:
12:4d7f1349d796
Parent:
11:cb48d596aa3e
Child:
13:00bbb0612e97
--- a/main.cpp	Thu May 03 22:34:03 2018 +0000
+++ b/main.cpp	Fri May 04 21:19:34 2018 +0000
@@ -34,41 +34,42 @@
     init();     // initialise
     welcome();  // display welcome screen till the user press start to start the game
 
-    render();  // drawing the initial frame 
+    render();  // drawing the initial frame
     wait(1.0f/fps);  // wait for one frame period
-    
-    // game loop
-    while (game.get_gameOver1()!=1) {
-        
+
+    // game loop executes untill check_gameOver() function return 1 to end the game
+    while (game.check_gameOver()!=1) {
+        // green LEDs turn on and red LEDs turn off
         g_pad.led(1, 0);
         g_pad.led(4, 0);
         g_pad.led(3, 2);
-        g_pad.led(6, 2);  
-        
+        g_pad.led(6, 2);
+
         game.read_input(g_pad);
-        game.update(g_pad,lcd);        
+        game.update(g_pad);
         render();
         wait(1.0f/fps);
-        
+
         while(g_pad.check_event(Gamepad::BACK_PRESSED) == true || sleep ==1) {
-            
+
             sleep=1;
-            ///red leds on , greens are off
+            // green LEDs turn off and red LED turn on
             g_pad.led(1, 2);
             g_pad.led(4, 2);
             g_pad.led(3, 0);
-            g_pad.led(6, 0); 
-            
+            g_pad.led(6, 0);
+            //stop the game seconds
+            game.time_stop();
             //sleep();
-            if(g_pad.check_event(Gamepad::START_PRESSED) == true){
+            //check if start button has been pressed to continue playing
+            if(g_pad.check_event(Gamepad::START_PRESSED) == true) {
                 sleep=0;
                 break;
             }
         }
-        
     }
     lcd.clear();
-    gameOver();
+    gameOver(); //game over screen show up with the maximum secs that has been reached
 
 }
 
@@ -87,7 +88,7 @@
 void render()
 {
     // first clear screen, re-draw and then refresh the LCD
-    lcd.clear();  
+    lcd.clear();
     game.draw(lcd);
     lcd.refresh();
 }
@@ -109,16 +110,16 @@
     }
 }
 
+// game over screen after the end of the game
+void gameOver()
+{
 
-void gameOver() {
-    
     lcd.printString("  Game Over!! ",0,1);
-    lcd.printString("   Try again ",0,3);
-    lcd.printString("    'reset' ",0,5);
-   //game.print_sec_over(lcd);
+    //print the maximum recorded seconds
+    game.print_travel_time(lcd);
     lcd.refresh();
-    
-    }
+
+}