ELEC2645 (2017/18) / Mbed 2 deprecated fy15raf

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
RehamFaqehi
Date:
Sun May 06 16:17:41 2018 +0000
Parent:
13:00bbb0612e97
Child:
15:658f1216ee84
Commit message:
Debugging strings and play again with start button have been added

Changed in this revision

GameEngine/GameEngine.cpp Show annotated file Show diff for this revision Revisions of this file
GameEngine/GameEngine.h Show annotated file Show diff for this revision Revisions of this file
Rocket/Rocket.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
tests.h Show annotated file Show diff for this revision Revisions of this file
--- a/GameEngine/GameEngine.cpp	Fri May 04 23:26:17 2018 +0000
+++ b/GameEngine/GameEngine.cpp	Sun May 06 16:17:41 2018 +0000
@@ -18,7 +18,7 @@
     _asteroid1.init(2);
     _asteroid2.init(3);
     _asteroid3.init(4);
-
+    time.reset();
     gameOver=0;
 }
 
@@ -81,6 +81,8 @@
             pad.leds_on();               //LEDs flashing
             wait(0.5);
             pad.leds_off();
+            //debugging 
+            printf("((collision occurs))\n" );
         }
     }
 }
@@ -103,6 +105,8 @@
             pad.leds_on();                  //LEDs flashing
             wait(0.5);
             pad.leds_off();
+            //debugging 
+            printf("((collision occurs))\n");
         }
     }
 }
@@ -125,6 +129,8 @@
             pad.leds_on();                  //LEDs flashing
             wait(0.5);
             pad.leds_off();
+            //debugging 
+            printf("((collision occurs))\n");
         }
     }
 }
@@ -158,7 +164,12 @@
     time.stop ();
     return gameOver;
 }
-
+void GameEngine::reset_gameOver(){
+    
+    //rest time and game over value to play again
+    time.reset();
+    gameOver=0;
+}
 
 void GameEngine::time_increment()
 {
--- a/GameEngine/GameEngine.h	Fri May 04 23:26:17 2018 +0000
+++ b/GameEngine/GameEngine.h	Sun May 06 16:17:41 2018 +0000
@@ -25,6 +25,8 @@
     void time_increment();
     void time_stop();
     void print_travel_time(N5110 &lcd);
+    void reset_gameOver();
+    int gameOver;
 
 private:
 
@@ -38,7 +40,6 @@
     Asteroid _asteroid3;
     Direction _d;
     float _mag;
-    int gameOver;
     Timer time;
     int _time;
 
--- a/Rocket/Rocket.cpp	Fri May 04 23:26:17 2018 +0000
+++ b/Rocket/Rocket.cpp	Sun May 06 16:17:41 2018 +0000
@@ -12,10 +12,11 @@
 
 void Rocket::init()
 {
-    //initialise the rocket position and speed
+    //initialise the rocket position, speed and collisions 
     _x = 15 ;
     _y = HEIGHT/2 ;
     _speed = 1;
+    _collision=0;
 }
 
 void Rocket::draw(N5110 &lcd)
--- a/main.cpp	Fri May 04 23:26:17 2018 +0000
+++ b/main.cpp	Sun May 06 16:17:41 2018 +0000
@@ -30,22 +30,28 @@
 int main()
 {
     //game will excute if all tests passed
-    #ifdef ALL_TESTS_H
+#ifdef ALL_TESTS_H
     int failures = Run_tests();
 
     if(failures > 0) return failures;
-    #endif
-    
+#endif
+
     int fps = 8;  // frames per second
     int sleep=0;
     init();     // initialise
     welcome();  // display welcome screen till the user press start to start the game
+    
+    //debugging
+    printf("\n....THE GAME STARTED :)..... \n\n");
 
     render();  // drawing the initial frame
     wait(1.0f/fps);  // wait for one frame period
 
-    // game loop executes untill check_gameOver() function return 1 to end the game
-    while (game.check_gameOver()!=1) {
+
+    // game loop executes
+    while (1) {
+        
+
         // green LEDs turn on and red LEDs turn off
         g_pad.led(1, 0);
         g_pad.led(4, 0);
@@ -59,6 +65,8 @@
 
         while(g_pad.check_event(Gamepad::BACK_PRESSED) == true || sleep ==1) {
 
+            printf("Waiting to contienue.....\n");
+
             sleep=1;
             // green LEDs turn off and red LED turn on
             g_pad.led(1, 2);
@@ -74,9 +82,23 @@
                 break;
             }
         }
+        if (game.check_gameOver()==1) { // if check_gameOver() function return 1 gameOver screen will be showen 
+            //debugging
+            printf("\n\n ....End of the game :)..... \n\n");
+
+            lcd.clear();
+            gameOver(); //game over screen will be shown with travelling period that has been reached 
+            
+            // reset to play again 
+            game.reset_gameOver();
+            init(); 
+            render();
+            
+            //debugging
+            printf("\n\n ....playing the game again :)..... \n\n");
+            
+        }
     }
-    lcd.clear();
-    gameOver(); //game over screen show up with the maximum secs that has been reached
 
 }
 
@@ -120,11 +142,13 @@
 // game over screen after the end of the game
 void gameOver()
 {
-
+    //game over secreen will be showen until start button is pressed
+    while ( g_pad.check_event(Gamepad::START_PRESSED) == false) {
     lcd.printString("  Game Over!! ",0,1);
     //print the maximum recorded seconds
     game.print_travel_time(lcd);
     lcd.refresh();
+    }
 
 }
 
--- a/tests.h	Fri May 04 23:26:17 2018 +0000
+++ b/tests.h	Sun May 06 16:17:41 2018 +0000
@@ -16,30 +16,30 @@
 ////////////////////Asteroid testing////////////////////////////
 
    // Run the Asteroid_test_movement test
-    printf("Testing Asteroid_movement.....\n");
+    printf(".....Testing Asteroid_movement.....\n");
     bool Asteroid_test_passed = Asteroid_movement();
 
     // Print out the result of all tests in Asteroid_movement
     if (Asteroid_test_passed) {
-        printf("...PASSED!\n");
+        printf("...PASSED!\n\n");
     }
     else {
-        printf("...FAILED!\n");
+        printf("...FAILED!\n\n");
         ++tests_failed; // Increase failures
     }
     
 ////////////////////Rocket testing////////////////////////////
 
     // Run the Rocket_test_movement test
-    printf("Testing Rocket_movement.....\n");
+    printf(".....Testing Rocket_movement.....\n");
     bool Rocket_test_passed = Rocket_movement();
     
     // Print out the result of all tests in rocket_movement
     if (Rocket_test_passed) {
-        printf("...PASSED!\n");
+        printf("...PASSED!\n\n");
     }
     else {
-        printf("...FAILED!\n");
+        printf("...FAILED!\n\n");
         ++tests_failed; // Increase failures
     }