Tuan Le / Mbed 2 deprecated AccelerometerProject

Dependencies:   MMA8452 N5110 PowerControl beep mbed

Revision:
4:c141e252d786
Parent:
3:1974db5993ef
Child:
5:c0a58a6916f2
--- a/Game.h	Mon May 04 15:55:32 2015 +0000
+++ b/Game.h	Mon May 04 21:14:23 2015 +0000
@@ -42,7 +42,8 @@
     void easyMode();
     void norMode();
     void hardMode();
-    int score; // Variable to store scores has a data type of interger
+    int score;
+    int scoArr[6];
     void reset();
 };
 
@@ -54,14 +55,21 @@
         if (accel.x > 2 || accel.x < -2) { //Easy mode: If the value of accelerator data exceed 2g, the score will increase by one unit
             score++;
             char scorebuffer[14];
-            int scorelength = sprintf(scorebuffer,"Score:%d",score); //Score will be displayed as unsigned Decimal Interger number
-            if (scorelength <=14) {
-                lcd.printString(scorebuffer,6,3);
-            }
+            sprintf(scorebuffer,"Score:%d",score); //Score will be displayed as unsigned Decimal Interger number
+            lcd.printString(scorebuffer,6,3);
         } else if (accel.x < 2 && accel.x > -2) { //Otherwise, if the score is unchange
             lcd.printString("EASY MODE",16,0); //Display a small notice to the user
         }
     }
+    if ((scoArr[0] == 0) || (scoArr[1] == 0)) {
+        scoArr[0] = score;
+    } else if((scoArr[0] > 0) && (scoArr[1] = 0)) {
+        scoArr[1] = score;
+    } else if(scoArr[0] > scoArr[1]) {
+        scoArr[1] = score;
+    } else if(scoArr[0] < scoArr[1]) {
+        scoArr[0] = score;
+    }
 }
 
 void Game::norMode()
@@ -72,14 +80,23 @@
         if (accel.x > 3 || accel.x < -3) { //Easy mode: If the value of accelerator data exceed 3g, the score will increase by one unit
             score++;
             char scorebuffer[14];
-            int scorelength = sprintf(scorebuffer,"Score:%d",score); //Score will be displayed as unsigned Decimal Interger number
-            if (scorelength <=14) {
-                lcd.printString(scorebuffer,6,3);
-            }
+            sprintf(scorebuffer,"Score:%d",score); //Score will be displayed as unsigned Decimal Interger number
+
+            lcd.printString(scorebuffer,6,3);
+
         } else if (accel.x < 3 && accel.x > -3) { //Otherwise, if the score is unchange
             lcd.printString("NORMAL MODE",9,0); //Display a small notice to the user
         }
     }
+    if ((scoArr[2] == 0) || (scoArr[3] == 0)) {
+        scoArr[2] = score;
+    } else if((scoArr[2] > 0) && (scoArr[3] = 0)) {
+        scoArr[3] = score;
+    } else if(scoArr[2] > scoArr[3]) {
+        scoArr[3] = score;
+    } else if(scoArr[2] < scoArr[3]) {
+        scoArr[2] = score;
+    }
 }
 
 void Game::hardMode()
@@ -90,14 +107,23 @@
         if (accel.x > 3.5 || accel.x < -3.5) { //Easy mode: If the value of accelerator data exceed 3.5g, the score will increase by one unit
             score++;
             char scorebuffer[14];
-            int scorelength = sprintf(scorebuffer,"Score:%d",score); //Score will be displayed as unsigned Decimal Interger number
-            if (scorelength <=14) {
-                lcd.printString(scorebuffer,6,3);
-            }
+            sprintf(scorebuffer,"Score:%d",score); //Score will be displayed as unsigned Decimal Interger number
+
+            lcd.printString(scorebuffer,6,3);
+
         } else if (accel.x < 3.5 && accel.x > -3.5) { //Otherwise, if the score is unchange
             lcd.printString("HARD MODE",16,0); //Display a small notice to the user
         }
     }
+    if ((scoArr[4] == 0) || (scoArr[5] == 0)) {
+        scoArr[4] = score;
+    } else if((scoArr[4] > 0) && (scoArr[5] = 0)) {
+        scoArr[5] = score;
+    } else if(scoArr[4] > scoArr[5]) {
+        scoArr[5] = score;
+    } else if(scoArr[4] < scoArr[5]) {
+        scoArr[4] = score;
+    }
 }
 
 void Game::reset()