Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MMA8452 N5110 PowerControl beep mbed
Diff: Game.h
- Revision:
- 3:1974db5993ef
- Parent:
- 2:57d1ed1f0ad3
- Child:
- 4:c141e252d786
diff -r 57d1ed1f0ad3 -r 1974db5993ef Game.h
--- a/Game.h Sat May 02 20:29:52 2015 +0000
+++ b/Game.h Mon May 04 15:55:32 2015 +0000
@@ -13,6 +13,13 @@
#include "N5110.h"
#include "Clock.h"
+Ticker gatimer;
+int gatimerFlag = 0;
+
+void gatimerExpired()
+{
+ gatimerFlag = 1; //Set flag for timer of the game
+}
class Game
{
@@ -32,31 +39,71 @@
/**
* The GameRule member function has a bsic rule of converting acceleration value into score
*/
- void GameRule();
+ void easyMode();
+ void norMode();
+ void hardMode();
int score; // Variable to store scores has a data type of interger
- void Reset();
+ void reset();
};
-void Game::GameRule ()
+void Game::easyMode ()
{
-
- 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);
+ if (gatimerFlag) {
+ gatimerFlag = 0;
+ accel = mma8452.readValues(); //Read the value from MMA8452 sensor
+ 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);
+ }
+ } 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
}
- } 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()
+void Game::norMode()
+{
+ if (gatimerFlag) {
+ gatimerFlag = 0;
+ accel = mma8452.readValues(); //Read the value from MMA8452 sensor
+ 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);
+ }
+ } 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
+ }
+ }
+}
+
+void Game::hardMode()
+{
+ if (gatimerFlag) {
+ gatimerFlag = 0;
+ accel = mma8452.readValues(); //Read the value from MMA8452 sensor
+ 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);
+ }
+ } 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
+ }
+ }
+}
+
+void Game::reset()
{
score = 0;
CClock = 60;
}
+
#endif
\ No newline at end of file