ELEC2645 (2018/19) / Mbed 2 deprecated el17ttds

Dependencies:   mbed N5110_tf

Revision:
1:8e319bd14b84
Parent:
0:7769e2ad5d7a
Child:
2:ee9b361ba6df
--- a/main.cpp	Sun May 05 11:50:04 2019 +0000
+++ b/main.cpp	Sun May 05 14:21:56 2019 +0000
@@ -8,7 +8,8 @@
     
     init();
     welcome();
-    menu();
+    string option = menu();
+    begin(option);
     
 }
 
@@ -51,7 +52,7 @@
     }
 }
 
-void menu() {
+string menu() {
     
     string option = "0";
     lcd.init();
@@ -79,56 +80,69 @@
     if (option == "A") {
         init();
         lcd.printString("  Play game?  ",0,0);
-        ask();
+        ask(option);
     } else if (option == "B") {
         init();
         lcd.printString("Play tutorial?",0,0);
-        ask();
-    } else if (option == "X") {
-        init();
-        highscores();
-    } else {
-        init();
-        credits();
+        ask(option);
     }
+    return option;
 }
 
-void ask() {
+void ask(string option) {
     
-    string option = "0";
+    int start = -1;
     lcd.printString("Are you sure?",0,3);
     lcd.printString("Back?   Start?",0,5);
     lcd.refresh();
     
-    while (option == "0") {
+    while (start == -1) {
         
         if (pad.check_event(Gamepad::START_PRESSED) == true) {
-            option = "start";
+            start = 1;
         } else if(pad.check_event(Gamepad::BACK_PRESSED) == true) {
-            option = "back";
+            start = 0;
         }
         wait(0.2);
     }
     
-    if (option == "back") {
+    if (start == 0) {
         menu();
+    }
+}
+
+void begin(string option) {
+    
+    init();
+    if (option == "A") {
+        play();
+    } else if (option == "B") {
+        tutorial();
+    } else if (option == "X") {
+        highscores();
     } else {
-        init();
-        lcd.printString("Start pressed",0,0);
-        lcd.refresh();
+        credits();
     }
 }
 
+void play() {
+    lcd.printString(" Playing!! ",0,0);
+    lcd.refresh();
+}
+
+void tutorial() {
+    lcd.printString(" Tutorial!! ",0,0);
+    lcd.refresh();
+}
+
 void highscores() {
     
-    init();
     lcd.printString(" Highscores!! ",0,0);
     lcd.refresh();
 }
 
 void credits() {
     
-    init();
     lcd.printString("   Credits!!   ",0,0);
     lcd.refresh();
 }
\ No newline at end of file