Dependencies:   mbed FATFileSystem

Revision:
17:98127ac75195
Parent:
16:c8d68cbd1ae2
--- a/GolfEngine/GolfEngine.cpp	Thu May 09 09:58:51 2019 +0000
+++ b/GolfEngine/GolfEngine.cpp	Thu May 09 12:01:42 2019 +0000
@@ -56,12 +56,7 @@
 void GolfEngine::check_end_level(N5110 &lcd, Gamepad &pad, SDFileSystem &sd)
 {
     if(_ball.check_hole(levels[_level].hole) == true) { //End of level sequence when level completed
-        /* UNCOMMENT FOR TESTING 
-        printf("Level %i Complete\n",_level+1);
-        print("Shots Taken = %i\n",_ball.get_shot_count());
-        printf("Total Shot Count = %i\n",_ball_get_total_shot_count());
-        printf("Begin Level %i /n",_level+2);
-        */
+
         drawCourseWalls(lcd,levels[_level].walls,levels[_level].wall_count); //draw walls for flash animation
         _level++; //increment level counter
         g_maj7_flash(pad, lcd); //flashes screen with g maj chord
@@ -111,7 +106,7 @@
     FILE *fp;
     fp = fopen("/sd/highscores.txt", "a"); //attempts to open highscores.txt
     if (fp == NULL) {  // if file does not exist then create new highscores.txt file
-         printf("Error! Unable to open file!\n");
+         printf("Error! Unable to open file!\n"); //print error message
     } else {
         fprintf(fp, "\n%i", value); //appends total shot count to highscores file
         fclose(fp);  //close file
@@ -120,11 +115,12 @@
 
 void GolfEngine::new_level(N5110 &lcd, SDFileSystem &sd) //called after ball is enters hole 
 { 
-    if(_level < 6) { //if all levels are completed
+    if(_level < 7) { //if all levels are completed
         printLevel(lcd);
         _ball.init(levels[_level].ball); //initialises ball in position for new level
-        
-    } else if (_level >= 6) { //if all levels not completed 
+    } else if (_level >= 7) { //if all levels not completed 
+    
+        _ball.init(levels[_level].ball); //to add the last levels shot count to the toal tally - ball position irrelevant
         lcd.printString("COURSE ",26,2);  
         lcd.printString("COMPLETE",22,3);  
         lcd.refresh();
@@ -132,12 +128,8 @@
         lcd.clear();
         char buffer[14];
         sprintf(buffer," %i",_ball.get_total_shot_count()); 
-        lcd.printString("YOUR SCORE",14,1);  
-        lcd.printString(buffer,30,2); //print final score 
-        /*UNCOMMENT FOR DEBUG
-        printf("Total Score = %i", _ball_get_total_shot_count());
-        printf("Game Over - Returning to menu"); 
-        */   
+        lcd.printString("YOUR SCORE:",14,1);  
+        lcd.printString(buffer,30,3); //print final score 
         lcd.refresh();
         wait(5);   
         file_append(_ball.get_total_shot_count(), sd); //appends final score to highscores.txt file
@@ -168,11 +160,11 @@
 void GolfEngine::g_maj7_flash(Gamepad &pad, N5110 &lcd) // Screen inverse flashing and buzzer plays G7 Chord with leds on
 { 
     pad.leds_on();
-    lcd.inverseMode();
+    lcd.inverseMode(); //pixels on = off & off = on
     lcd.refresh();
     pad.tone(783.99, 0.25); //play note (G5)
     wait(0.25);
-    lcd.normalMode();
+    lcd.normalMode(); 
     lcd.refresh();
     pad.tone(987.77, 0.25); //play note (B5)
     wait(0.25);