My ELEC2645 project. Nikollao Sulollari. 200804685

Dependencies:   N5110 SoftPWM mbed

Fork of Treasure_Hunt by ELEC2645 (2015/16)

Revision:
17:2d424db3975f
Parent:
16:a6ca6858af24
Child:
18:5405ee7e243b
--- a/main.h	Mon May 02 08:56:08 2016 +0000
+++ b/main.h	Mon May 02 11:02:36 2016 +0000
@@ -34,28 +34,15 @@
 
 /**
 @nameSpace blue_led
-@brief output for status of blue LED
+@brief output for status of blue LED, lights when game tool is loaded
 */
 DigitalOut blue_led(PTA1);
 
 /**
-@nameSpace left_led
-@brief output for status of left LED
-*/
-DigitalOut left_led(PTB23);
-
-/**
-@nameSpace centre_led
-@brief output for status of centre LED
+@nameSpace led_output
+@brief output for status of left tries for the user to win the game
 */
-DigitalOut centre_led(PTA2);
-
-/**
-@nameSpace right_LED
-@brief output for status of right LED
-*/
-DigitalOut right_led(PTC2);
-
+BusOut led_output(PTC2,PTA2,PTB23);
 
 /**
 @nameSpace lcd
@@ -316,6 +303,10 @@
 
 volatile float game_speed = 0.05; /*!< value is set to the ticker, allows user to select game speed */
 
+int fsm[4] = {7,6,4,0}; /*!< array of elements in the FSM, each element is the output of the counter */
+
+int fsm_state = 0; /*!<  variable is used to access the array of states and produce an output */
+
 int reset = 0; /*!< used to save current level of difficulty */
 
 int objectX = 0; /*!< used to move obstacles in the x-axis */
@@ -476,21 +467,21 @@
     } 
     else if (level == 8) {
 
-        //ticker.detach();
+        ticker.detach();
         lcd.clear();
         lcd.printString("Well done!",0,0);
         lcd.refresh();
-        timeout.attach(&timeout_isr,2);
-        sleep();
+        wait(2);
         lcd.clear();
         lcd.printString("Play again",0,0);
         lcd.drawCircle(70,4,2,1);
         lcd.refresh();
-        g_button1_flag = 0;
+        g_button_flag = 0;
+        
         while(1) {
-            if  (g_button1_flag) {
+            if  (g_button_flag) {
 
-                g_button1_flag = 0;
+                g_button_flag = 0;
                 level = 0;
                 // play++;
                 lcd.clear();
@@ -917,20 +908,74 @@
             }
             if (check > 7) {
 
-                lcd.printString(bit,0,0);
+                tries--;
+                //if tries
+
+                lcd.printString("BANG!",0,0);
                 lcd.refresh();
-                tries--;
-                if(tries == 2) {
-                    right_led = 0;
-                }else if (tries == 1) {
-                    centre_led = 0;
-                }else if(tries == 0){
-                    left_led = 0;
-                    //gameOver();
+                wait(2);
+                lcd.clear();
+                
+                if (tries == 2) {
+                    
+                    lcd.printString("Ready.",20,1);
+                    lcd.refresh();
+                    wait(0.5);
+                    lcd.printString("Ready..",20,1);
+                    lcd.refresh();
+                    wait(0.5);
+                    lcd.printString("Ready...",20,1);
+                    lcd.refresh();
+                    wait(1);
+                    lcd.printString("GO!",31,2);
+                    lcd.refresh();
+                    wait(1);
+                    lcd.clear();
+                    fsm_state = 1; ///2 lives left
+                } 
+                else if (tries == 1) {
+                    
+                    lcd.clear();
+                    lcd.printString("Last Chance!",10,2);
+                    lcd.refresh();
+                    wait(1);
+                    fsm_state = 2; //1 life left
+                } 
+                else if (tries == 0) {
+                    
+                    fsm_state = 3;
+                    led_output=fsm[fsm_state];
+                    lcd.clear();
+                    lcd.printString("Game Over!",0,0);
+                    lcd.refresh();
+                    wait(1);
+
+                    //ticker.detach();
+                    lcd.clear();
+                    lcd.printString("Play again",0,0);
+                    lcd.drawCircle(70,4,2,1);
+                    lcd.refresh();
+                    g_button_flag = 0;
+
+                    while(1) {
+                        if  (g_button_flag) {
+
+                            g_button_flag = 0;
+                            level = 0;
+                            fsm_state = 0;
+                            led_output=fsm[fsm_state];
+                            lcd.clear();
+                            main();
+                        }
+                        sleep();
+                    }
+                    
                 }
-                wait(2);
                 heroX = 0;
                 heroY = 0;
+                rectY = 0;
+                circleX = 0;
+                led_output=fsm[fsm_state];
             }
 
         }