Game codes for Pokemon Academy Yiu Fai Kwok - 201198802 I have read the University Regulations on Plagiarism and state that the work covered by this declaration is my own and does not contain any unacknowledged work from other sources.

Dependencies:   mbed FXOS8700CQ mbed-rtos

Revision:
22:f8f36e88b2ca
Parent:
13:02002658e718
Child:
23:4a070960817a
--- a/Exam/Exam.cpp	Sun Apr 28 18:04:23 2019 +0000
+++ b/Exam/Exam.cpp	Sun Apr 28 18:58:10 2019 +0000
@@ -60,7 +60,6 @@
         //music.gym(pad, !finished);
         switch (currentPage) {
             case PAGE_1:
-                pad.init_input();
                 lcd.clear();
                 lcd.printString("Question 1",0,0);
                 lcd.printString("What is the",0,1);
@@ -69,12 +68,11 @@
                 lcd.printString("of a circuit",0,4);
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_2;}
-                if(pad.get_direction() == N){currentPage = PAGE_1;}
+                if(pad.get_direction() == S){currentPage = PAGE_2; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_1; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_2:
-                pad.init_input();
                 lcd.clear();
                 lcd.printString("formed by a",0,0);
                 lcd.printString("50k resistor",0,1);
@@ -83,12 +81,11 @@
                 lcd.printString("series?",0,4);
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_3;}
-                if(pad.get_direction() == N){currentPage = PAGE_1;}
+                if(pad.get_direction() == S){currentPage = PAGE_3; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_1; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_3:
-                pad.init_input();
                 lcd.clear();
                 if (point > 0){
                     lcd.printString("A. 26.5kHz",0,2);
@@ -104,20 +101,21 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, (int*)up);
                 lcd.refresh();
-                if(pad.get_direction() == N){currentPage = PAGE_2;}
+                if(pad.get_direction() == N){currentPage = PAGE_2; pad.init_input();}
                 if(pad.check_event(Gamepad::A_PRESSED) == true){
                     score++;
                     currentPage = PAGE_4;
+                    pad.init_input();
                 }
                 if((pad.check_event(Gamepad::B_PRESSED) == true)
                 || (pad.check_event(Gamepad::X_PRESSED) == true)
                 || (pad.check_event(Gamepad::Y_PRESSED) == true)){
                     currentPage = PAGE_4;
+                    pad.init_input();
                 }
                 wait(1.0f/fps);
             break;
             case PAGE_4:
-                pad.init_input();
                 lcd.clear();
                 lcd.printString("Question 2",0,0);
                 lcd.printString("What is the",0,1);
@@ -126,24 +124,22 @@
                 lcd.printString("1/(6+5cos(x))",0,4);
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_5;}
-                if(pad.get_direction() == N){currentPage = PAGE_4;}
+                if(pad.get_direction() == S){currentPage = PAGE_5; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_4; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_5:
-                pad.init_input();
                 lcd.clear();
                 lcd.printString("with respect",0,0);
                 lcd.printString("to x for ",0,1);
                 lcd.printString("[0,pi/2]?",0,2);
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_6;}
-                if(pad.get_direction() == N){currentPage = PAGE_4;}
+                if(pad.get_direction() == S){currentPage = PAGE_6; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_4; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_6:
-                pad.init_input();
                 lcd.clear();
                 if(point > 1) {
                     lcd.printString("A. 0.1354",0,2);
@@ -159,20 +155,21 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, (int*)up);
                 lcd.refresh();
-                if(pad.get_direction() == N){currentPage = PAGE_5;}
+                if(pad.get_direction() == N){currentPage = PAGE_5; pad.init_input();}
                 if(pad.check_event(Gamepad::Y_PRESSED) == true){
                     score++;
                     currentPage = PAGE_7;
+                    pad.init_input();
                 }
                 if((pad.check_event(Gamepad::A_PRESSED) == true)
                 || (pad.check_event(Gamepad::B_PRESSED) == true)
                 || (pad.check_event(Gamepad::X_PRESSED) == true)){
                     currentPage = PAGE_7;
+                    pad.init_input();
                 }
                 wait(1.0f/fps);
             break;
             case PAGE_7:
-                pad.init_input();
                 lcd.clear();
                 lcd.printString("Question 3",0,0);
                 lcd.printString("What is the",0,1);
@@ -181,23 +178,21 @@
                 lcd.printString("tan(x)",0,4);
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_8;}
-                if(pad.get_direction() == N){currentPage = PAGE_7;}
+                if(pad.get_direction() == S){currentPage = PAGE_8; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_7; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_8:
-                pad.init_input();
                 lcd.clear();
                 lcd.printString("with respect",0,0);
                 lcd.printString("to x?",0,1);
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_9;}
-                if(pad.get_direction() == N){currentPage = PAGE_7;}
+                if(pad.get_direction() == S){currentPage = PAGE_9; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_7; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_9:
-                pad.init_input();
                 lcd.clear();
                 if(point > 2) {
                     lcd.printString("A. -ln|cos(x)|",0,2);
@@ -213,26 +208,27 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, (int*)up);
                 lcd.refresh();
-                if(pad.get_direction() == N){currentPage = PAGE_8;}
+                if(pad.get_direction() == N){currentPage = PAGE_8; pad.init_input();}
                 if(pad.check_event(Gamepad::A_PRESSED) == true){
                     score++;
                     currentPage = PAGE_10;
+                    pad.init_input();
                 }
                 if((pad.check_event(Gamepad::B_PRESSED) == true)
                 || (pad.check_event(Gamepad::Y_PRESSED) == true)
                 || (pad.check_event(Gamepad::X_PRESSED) == true)){
                     currentPage = PAGE_10;
+                    pad.init_input();
                 }
                 wait(1.0f/fps);
             break;
             case PAGE_10:
-                pad.init_input();
                 lcd.clear();
                 lcd.printString("EXAM",0,0);
                 lcd.printString("COMPLETE",0,1);
                 lcd.printString("PRESS START",0,5);
                 lcd.refresh();
-                if(pad.check_event(Gamepad::START_PRESSED) == true) {finished = true;}
+                if(pad.check_event(Gamepad::START_PRESSED) == true) {finished = true; pad.init_input();}
                 wait(1.0f/fps);
             break;
         }
@@ -272,8 +268,8 @@
                 lcd.printString("Calculate",0,4);
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_2;}
-                if(pad.get_direction() == N){currentPage = PAGE_1;}
+                if(pad.get_direction() == S){currentPage = PAGE_2; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_1; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_2:
@@ -285,8 +281,8 @@
                 lcd.printString("by it.",0,4);
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_3;}
-                if(pad.get_direction() == N){currentPage = PAGE_1;}
+                if(pad.get_direction() == S){currentPage = PAGE_3; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_1; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_3:
@@ -305,15 +301,17 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, (int*)up);
                 lcd.refresh();
-                if(pad.get_direction() == N){currentPage = PAGE_2;}
+                if(pad.get_direction() == N){currentPage = PAGE_2; pad.init_input();}
                 if(pad.check_event(Gamepad::B_PRESSED) == true){
                     score++;
                     currentPage = PAGE_4;
+                    pad.init_input();
                 }
                 if((pad.check_event(Gamepad::A_PRESSED) == true)
                 || (pad.check_event(Gamepad::X_PRESSED) == true)
                 || (pad.check_event(Gamepad::Y_PRESSED) == true)){
                     currentPage = PAGE_4;
+                    pad.init_input();
                 }
                 wait(1.0f/fps);
             break;
@@ -326,8 +324,8 @@
                 lcd.printString("closed for",0,4);
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_5;}
-                if(pad.get_direction() == N){currentPage = PAGE_4;}
+                if(pad.get_direction() == S){currentPage = PAGE_5; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_4; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_5:
@@ -339,8 +337,8 @@
                 lcd.printString("frequency?",0,4);
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_6;}
-                if(pad.get_direction() == N){currentPage = PAGE_4;}
+                if(pad.get_direction() == S){currentPage = PAGE_6; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_4; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_6:
@@ -359,15 +357,17 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, (int*)up);
                 lcd.refresh();
-                if(pad.get_direction() == N){currentPage = PAGE_5;}
+                if(pad.get_direction() == N){currentPage = PAGE_5; pad.init_input();}
                 if(pad.check_event(Gamepad::A_PRESSED) == true){
                     score++;
                     currentPage = PAGE_7;
+                    pad.init_input();
                 }
                 if((pad.check_event(Gamepad::Y_PRESSED) == true)
                 || (pad.check_event(Gamepad::B_PRESSED) == true)
                 || (pad.check_event(Gamepad::X_PRESSED) == true)){
                     currentPage = PAGE_7;
+                    pad.init_input();
                 }
                 wait(1.0f/fps);
             break;
@@ -380,8 +380,8 @@
                 lcd.printString("and t<6. What",0,4);
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_8;}
-                if(pad.get_direction() == N){currentPage = PAGE_7;}
+                if(pad.get_direction() == S){currentPage = PAGE_8; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_7; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_8:
@@ -391,8 +391,8 @@
                 lcd.printString("t=0?",0,2);
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_9;}
-                if(pad.get_direction() == N){currentPage = PAGE_7;}
+                if(pad.get_direction() == S){currentPage = PAGE_9; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_7; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_9:
@@ -411,15 +411,17 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, (int*)up);
                 lcd.refresh();
-                if(pad.get_direction() == N){currentPage = PAGE_8;}
+                if(pad.get_direction() == N){currentPage = PAGE_8; pad.init_input();}
                 if(pad.check_event(Gamepad::Y_PRESSED) == true){
                     score++;
                     currentPage = PAGE_10;
+                    pad.init_input();
                 }
                 if((pad.check_event(Gamepad::B_PRESSED) == true)
                 || (pad.check_event(Gamepad::A_PRESSED) == true)
                 || (pad.check_event(Gamepad::X_PRESSED) == true)){
                     currentPage = PAGE_10;
+                    pad.init_input();
                 }
                 wait(1.0f/fps);
             break;
@@ -429,7 +431,7 @@
                 lcd.printString("COMPLETE",0,1);
                 lcd.printString("PRESS START",0,5);
                 lcd.refresh();
-                if(pad.check_event(Gamepad::START_PRESSED) == true) {finished = true;}
+                if(pad.check_event(Gamepad::START_PRESSED) == true) {finished = true; pad.init_input();}
                 wait(1.0f/fps);
             break;
         }
@@ -461,7 +463,6 @@
         //music.gym(pad, !finished);
         switch (currentPage) {
             case PAGE_1:
-                pad.init_input();
                 lcd.clear();
                 if (point > 0){
                     lcd.printString("Question 1",0,0);
@@ -476,12 +477,11 @@
                 }
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_2;}
-                if(pad.get_direction() == N){currentPage = PAGE_1;}
+                if(pad.get_direction() == S){currentPage = PAGE_2; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_1; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_2:
-                pad.init_input();
                 lcd.clear();
                 if (point > 0){
                     lcd.printString("A. ",0,2);
@@ -497,20 +497,21 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, (int*)up);
                 lcd.refresh();
-                if(pad.get_direction() == N){currentPage = PAGE_1;}
+                if(pad.get_direction() == N){currentPage = PAGE_1; pad.init_input();}
                 if(pad.check_event(Gamepad::A_PRESSED) == true){
                     score++;
                     currentPage = PAGE_3;
+                    pad.init_input();
                 }
                 if((pad.check_event(Gamepad::B_PRESSED) == true)
                 || (pad.check_event(Gamepad::X_PRESSED) == true)
                 || (pad.check_event(Gamepad::Y_PRESSED) == true)){
                     currentPage = PAGE_3;
+                    pad.init_input();
                 }
                 wait(1.0f/fps);
             break;
             case PAGE_3:
-                pad.init_input();
                 lcd.clear();
                 if (point > 1){
                     lcd.printString("Question 2",0,0);
@@ -525,12 +526,11 @@
                 }
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_4;}
-                if(pad.get_direction() == N){currentPage = PAGE_3;}
+                if(pad.get_direction() == S){currentPage = PAGE_4; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_3; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_4:
-                pad.init_input();
                 lcd.clear();
                 if (point > 1){
                     lcd.printString("A. ",0,2);
@@ -546,20 +546,21 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, (int*)up);
                 lcd.refresh();
-                if(pad.get_direction() == N){currentPage = PAGE_3;}
+                if(pad.get_direction() == N){currentPage = PAGE_3; pad.init_input();}
                 if(pad.check_event(Gamepad::B_PRESSED) == true){
                     score++;
                     currentPage = PAGE_5;
+                    pad.init_input();
                 }
                 if((pad.check_event(Gamepad::A_PRESSED) == true)
                 || (pad.check_event(Gamepad::X_PRESSED) == true)
                 || (pad.check_event(Gamepad::Y_PRESSED) == true)){
                     currentPage = PAGE_5;
+                    pad.init_input();
                 }
                 wait(1.0f/fps);
             break;
             case PAGE_5:
-                pad.init_input();
                 lcd.clear();
                 if (point > 2){
                     lcd.printString("Question 3",0,0);
@@ -574,12 +575,11 @@
                 }
                 lcd.drawSprite(39, 44, 4, 7, (int*)down);
                 lcd.refresh();
-                if(pad.get_direction() == S){currentPage = PAGE_6;}
-                if(pad.get_direction() == N){currentPage = PAGE_5;}
+                if(pad.get_direction() == S){currentPage = PAGE_6; pad.init_input();}
+                if(pad.get_direction() == N){currentPage = PAGE_5; pad.init_input();}
                 wait(1.0f/fps);
             break;
             case PAGE_6:
-                pad.init_input();
                 lcd.clear();
                 if (point > 2){
                     lcd.printString("A. ",0,2);
@@ -595,26 +595,27 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, (int*)up);
                 lcd.refresh();
-                if(pad.get_direction() == N){currentPage = PAGE_5;}
+                if(pad.get_direction() == N){currentPage = PAGE_5; pad.init_input();}
                 if(pad.check_event(Gamepad::Y_PRESSED) == true){
                     score++;
                     currentPage = PAGE_7;
+                    pad.init_input();
                 }
                 if((pad.check_event(Gamepad::A_PRESSED) == true)
                 || (pad.check_event(Gamepad::X_PRESSED) == true)
                 || (pad.check_event(Gamepad::B_PRESSED) == true)){
                     currentPage = PAGE_7;
+                    pad.init_input();
                 }
                 wait(1.0f/fps);
             break;
             case PAGE_7:
-                pad.init_input();
                 lcd.clear();
                 lcd.printString("EXAM",0,0);
                 lcd.printString("COMPLETE",0,1);
                 lcd.printString("PRESS START",0,5);
                 lcd.refresh();
-                if(pad.check_event(Gamepad::START_PRESSED) == true) {finished = true;}
+                if(pad.check_event(Gamepad::START_PRESSED) == true) {finished = true; pad.init_input();}
                 wait(1.0f/fps);
             break;
         }