Dependencies:   MMA8452 N5110 PowerControl beep mbed

Revision:
2:57d1ed1f0ad3
Parent:
1:92f77de19aad
Child:
3:1974db5993ef
--- a/Game.h	Mon Apr 20 20:00:20 2015 +0000
+++ b/Game.h	Sat May 02 20:29:52 2015 +0000
@@ -11,7 +11,7 @@
 #include "mbed.h"
 #include "MMA8452.h"
 #include "N5110.h"
-
+#include "Clock.h"
 
 
 class Game
@@ -21,7 +21,7 @@
     * @param The variable Score is used to store score of user when
     * @param the accelerometer excessed a threshold value.
     */
-    int score; // Variable to store scores has a data type of interger
+
 
     /**
     * @param The acceleration variable recalled from MMA8452.h
@@ -33,29 +33,30 @@
     * The GameRule member function has a bsic rule of converting acceleration value into score
     */
     void GameRule();
+    int score; // Variable to store scores has a data type of interger
+    void Reset();
 };
 
 void Game::GameRule ()
 {
-    
-    score = 0; // The score is set to zero
 
-    while(1) {
-        accel = mma8452.readValues(); // Read the value from MMA8452 sensor
-        if (accel.y > 3) { // If the value of accelerator data exceed 3g, the score will increase by one unit
-            score++;
-            char scorebuffer[14];
+    accel = mma8452.readValues(); // Read the value from MMA8452 sensor
+    if (accel.x > 2 || accel.x < -2) { // 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 Signed Decimal Interger number
-            if (scorelength <=14)
-                lcd.printString(scorebuffer,3,3);
-            wait(0.1);
-
-        } else {
-            score = score; // Otherwise, the score is unchange
-            lcd.printString("Shake harder",0,0); // Display a small notice to the user
+        int scorelength = sprintf(scorebuffer,"Score:%d",score); //Score will be displayed as Signed Decimal Interger number
+        if (scorelength <=14) {
+            lcd.printString(scorebuffer,3,3);
         }
-        wait(0.1);
+    } else if (accel.x < 2 && accel.x > -2) { // Otherwise, if the score is unchange
+        lcd.printString("Have a shake",0,0); // Display a small notice to the user
     }
 }
+
+void Game::Reset()
+{
+    score = 0;
+    CClock = 60;
+}
 #endif
\ No newline at end of file