ELEC2645 (2018/19) / Mbed 2 deprecated 2645_Project_SiutingWong201186503

Dependencies:   mbed

Revision:
13:c3c58d50a571
Parent:
12:660458c41c8e
Child:
15:749c595b19e2
--- a/main.cpp	Thu May 09 04:26:16 2019 +0000
+++ b/main.cpp	Thu May 09 05:25:04 2019 +0000
@@ -227,7 +227,7 @@
     wait(0.70);
     pad.tone(587.3,0.63);
     wait(0.70);
-    while (pad.check_event(Gamepad::START_PRESSED) == false) { // add animation
+    while (pad.check_event(Gamepad::START_PRESSED) == false) { // animation loop until start button is pressed
         lcd.clear();
         lcd.printString("Eternity Stone",0,0);
         lcd.printString("Start story",9,4);
@@ -243,7 +243,7 @@
     }
 }
 
-void introduction() {
+void introduction() { // background story
     lcd.clear();
     lcd.printString("Five years",12,0);
     lcd.refresh();
@@ -256,11 +256,11 @@
     wait(1.0);
     lcd.printString("(Press start)",3,1);
     wait(1.0);
-    while (pad.check_event(Gamepad::START_PRESSED) == false) {
+    while (pad.check_event(Gamepad::START_PRESSED) == false) { // while-looping until the button is on
         lcd.refresh();
         wait(0.5);
     }
-    lcd.clear();
+    lcd.clear(); // background story
     lcd.printString("You are a",12,0);
     lcd.printString("member of",15,1);
     lcd.printString("Avengers and",6,2);
@@ -269,11 +269,11 @@
     lcd.printString("Quantum realm",3,5);
     lcd.refresh();
     wait(1.0);
-    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
+    while ( pad.check_event(Gamepad::START_PRESSED) == false) { // while-looping until the button is on
         lcd.refresh();
         wait(0.5);
     }
-    while (pad.check_event(Gamepad::START_PRESSED) == false) {
+    while (pad.check_event(Gamepad::START_PRESSED) == false) { // tutorial with animation
         lcd.clear();
         lcd.printString("Use your",18,0);
         lcd.printString("joystick to",9,1);
@@ -302,7 +302,8 @@
         lcd.refresh();
         wait(0.5);
     }
-    while (pad.check_event(Gamepad::START_PRESSED) == false) {
+    
+    while (pad.check_event(Gamepad::START_PRESSED) == false) { // tutorial with animation
         lcd.clear();
         lcd.printString("try not to",12,0);
         lcd.printString("interrupt",15,1);
@@ -328,25 +329,21 @@
         lcd.refresh();
         wait(0.5);
     }
-    while (pad.check_event(Gamepad::START_PRESSED) == false) {
-        lcd.clear();
-        lcd.printString("retrieve 6",12,0);
-        lcd.printString("stones and",12,1);
-        lcd.printString("win the game",6,2);
-        lcd.printString("God speed",15,3);
-        lcd.printString("Avengers!",15,4);
-        lcd.refresh();
+    
+    lcd.clear(); // last message before the game begins
+    lcd.printString("retrieve 6",12,0);
+    lcd.printString("stones and",12,1);
+    lcd.printString("win the game",6,2);
+    lcd.printString("God speed",15,3);
+    lcd.printString("Avengers!",15,4);
+    lcd.refresh();
+    wait(0.5);
+    
+    while (pad.check_event(Gamepad::START_PRESSED) == false) { //sparking leds
         pad.leds_on();
-        wait(0.5);
-        lcd.clear();
-        lcd.printString("retrieve 6",12,0);
-        lcd.printString("stones and",12,1);
-        lcd.printString("win the game",6,2);
-        lcd.printString("God speed",15,3);
-        lcd.printString("Avengers!",15,4);
-        lcd.refresh();
+        wait(0.25);
         pad.leds_off();
-        wait(0.5);
+        wait(0.25);
     }
 }
 
@@ -358,10 +355,13 @@
 }
 
 void fingersnap() {
-    lcd.clear();
-    lcd.printString("Congrat!!",15,1);
+    lcd.clear(); // at this point the game has broken the while loop, clear screen to display congrat message
+    lcd.printString("Congrat!!",15,0);
+    lcd.printString("Credit: STWong",0,1);
+    lcd.printString("201186503",15,2);
     lcd.refresh();
-    pad.tone(440.00,0.21);
+    
+    pad.tone(440.00,0.21); // avenger theme again
     wait(0.21);
     pad.tone(587.3,0.63);
     wait(0.63);
@@ -387,7 +387,7 @@
     wait(0.70);
     pad.tone(587.3,0.63);
     wait(0.70);
-    while (pad.check_event(Gamepad::START_PRESSED) == false) {
+    while (pad.check_event(Gamepad::START_PRESSED) == false) { // enter loop waiting to restart the game
         lcd.printString("press start",9,4);
         lcd.printString("to return",15,5);
         lcd.refresh();
@@ -399,12 +399,13 @@
 }
 
 void endgame() {
-    lcd.clear();
+    lcd.clear(); //break the while loop and enter gameover
     lcd.printString("Mr.Stark",18,1);
     lcd.printString("I don't feel",6,2);
     lcd.printString("so good ...",9,3);
     lcd.refresh();
-    pad.tone(587.3,0.63);
+    
+    pad.tone(587.3,0.63); // play sad music when lose
     wait(0.63);
     pad.tone(0.0,0.06);
     wait(0.06);
@@ -434,7 +435,7 @@
     wait(0.21);
     pad.tone(587.3,0.42);
     wait(0.42);
-    while (pad.check_event(Gamepad::START_PRESSED) == false) {
+    while (pad.check_event(Gamepad::START_PRESSED) == false) { // enter loop waiting to restart the game
         lcd.printString("press start",9,4);
         lcd.printString("to return",15,5);
         lcd.refresh();