Hugo Hu / Mbed 2 deprecated BRAVEHEART

Dependencies:   mbed N5110 ShiftReg PinDetect

Revision:
7:678873947b29
Parent:
5:100d960fc6d5
Child:
8:9ac6a428fa26
--- a/StateManger.cpp	Fri May 01 09:44:38 2015 +0000
+++ b/StateManger.cpp	Fri May 01 18:10:59 2015 +0000
@@ -5,7 +5,7 @@
 {
     if (currentState != 0)      // if a state exist
         delete currentState;    // delete the old state
-        
+
     // Create new state
     switch (newState)
     {
@@ -13,10 +13,11 @@
             currentState = new MainMenu(this, lcd, input);
         break;
         
-        // TODO: Make classes for the other states, currently all  than MAIN_MENU will give error
         case GAME:
-        //break;
+            currentState = new Game(this, lcd, input);
+        break;
         
+        // TODO: Make classes for the other states.
         case SUBMIT_HIGHSCORE:
         //break;
         
@@ -28,12 +29,30 @@
     }
 }
 
-void StateManager::update(time_t dt)
+void StateManager::requestStateChange(MainState requestedState)
 {
+    if (nextState != NO_STATE)
+        error("Invalid - can't request new state before the first request has been processed!");
+        
+    nextState = requestedState;
+}
+
+void StateManager::update(float dt)
+{       
     currentState->update(dt);
 }
 
 void StateManager::render()
 {
     currentState->render();
+}
+
+void StateManager::processRequest()
+{
+    // Check if there has been a request to change the state
+    if (nextState != NO_STATE)
+    {
+        changeState(nextState);
+        nextState = NO_STATE;       // reset, state has been changed
+    }
 }
\ No newline at end of file