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:
6:9104692d6c8c
Parent:
5:bc0691d02fd5
--- a/Exam/Exam.cpp	Mon Apr 08 00:41:25 2019 +0000
+++ b/Exam/Exam.cpp	Wed Apr 10 17:52:45 2019 +0000
@@ -57,11 +57,10 @@
     bool finished = false;
     
     while(pad.check_event(Gamepad::START_PRESSED) == false){
-        //music.gym(pad, !finished);
+        //thread.start(music.gym(pad, !finished));
         switch (currentPage) {
             case PAGE_1:
                 lcd.clear();
-                
                 lcd.printString("Question 1",0,0);
                 lcd.printString("What is the",0,1);
                 lcd.printString("cut off",0,2);
@@ -70,12 +69,10 @@
                 lcd.drawSprite(39, 44, 4, 7, down);
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_2;}
-                if(pad.get_direction() == N){currentPage = PAGE_1;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_2:
                 lcd.clear();
-                
                 lcd.printString("formed by a",0,0);
                 lcd.printString("50k resistor",0,1);
                 lcd.printString("and capacitor",0,2);
@@ -85,11 +82,10 @@
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_3;}
                 if(pad.get_direction() == N){currentPage = PAGE_1;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_3:
                 lcd.clear();
-                pad.init();
                 if (point > 0){
                     lcd.printString("A. 26.5kHz",0,2);
                     lcd.printString("B. 2.61MHz",0,3);
@@ -104,7 +100,6 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, up);
                 lcd.refresh();
-                wait(2.0f/fps);
                 if(pad.get_direction() == N){currentPage = PAGE_2;}
                 if(pad.check_event(Gamepad::A_PRESSED) == true){
                     score++;
@@ -115,11 +110,10 @@
                 || (pad.check_event(Gamepad::Y_PRESSED) == true)){
                     currentPage = PAGE_4;
                 }
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_4:
                 lcd.clear();
-                
                 lcd.printString("Question 2",0,0);
                 lcd.printString("What is the",0,1);
                 lcd.printString("integration",0,2);
@@ -128,12 +122,10 @@
                 lcd.drawSprite(39, 44, 4, 7, down);
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_5;}
-                if(pad.get_direction() == N){currentPage = PAGE_4;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_5:
                 lcd.clear();
-                
                 lcd.printString("with respect",0,0);
                 lcd.printString("to x for ",0,1);
                 lcd.printString("[0,pi/2]?",0,2);
@@ -141,11 +133,10 @@
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_6;}
                 if(pad.get_direction() == N){currentPage = PAGE_4;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_6:
                 lcd.clear();
-                pad.init();
                 if(point > 1) {
                     lcd.printString("A. 0.1354",0,2);
                     lcd.printString("B. 2.617",0,3);
@@ -160,7 +151,6 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, up);
                 lcd.refresh();
-                wait(2.0f/fps);
                 if(pad.get_direction() == N){currentPage = PAGE_5;}
                 if(pad.check_event(Gamepad::Y_PRESSED) == true){
                     score++;
@@ -171,11 +161,10 @@
                 || (pad.check_event(Gamepad::X_PRESSED) == true)){
                     currentPage = PAGE_7;
                 }
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_7:
                 lcd.clear();
-                
                 lcd.printString("Question 3",0,0);
                 lcd.printString("What is the",0,1);
                 lcd.printString("integration",0,2);
@@ -184,22 +173,19 @@
                 lcd.drawSprite(39, 44, 4, 7, down);
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_8;}
-                if(pad.get_direction() == N){currentPage = PAGE_7;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_8:
                 lcd.clear();
-                
                 lcd.printString("with respect",0,0);
                 lcd.printString("to x?",0,1);
                 lcd.drawSprite(39, 44, 4, 7, down);
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_9;}
                 if(pad.get_direction() == N){currentPage = PAGE_7;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_9:
-                pad.init();
                 lcd.clear();
                 if(point > 2) {
                     lcd.printString("A. -ln|cos(x)|",0,2);
@@ -215,7 +201,6 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, up);
                 lcd.refresh();
-                wait(2.0f/fps);
                 if(pad.get_direction() == N){currentPage = PAGE_8;}
                 if(pad.check_event(Gamepad::A_PRESSED) == true){
                     score++;
@@ -226,17 +211,16 @@
                 || (pad.check_event(Gamepad::X_PRESSED) == true)){
                     currentPage = PAGE_10;
                 }
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_10:
                 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;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
         }
     }
@@ -267,7 +251,6 @@
         //music.gym(pad, !finished);
         switch (currentPage) {
             case PAGE_1:
-                
                 lcd.clear();
                 lcd.printString("Question 1",0,0);
                 lcd.printString("A GaAs LED",0,1);
@@ -278,10 +261,9 @@
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_2;}
                 if(pad.get_direction() == N){currentPage = PAGE_1;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_2:
-                
                 lcd.clear();
                 lcd.printString("the longest",0,0);
                 lcd.printString("wavelength",0,1);
@@ -292,10 +274,9 @@
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_3;}
                 if(pad.get_direction() == N){currentPage = PAGE_1;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_3:
-                pad.init();
                 lcd.clear();
                 if (point > 0){
                     lcd.printString("A. 913.52nm",0,2);
@@ -311,7 +292,6 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, up);
                 lcd.refresh();
-                wait(2.0f/fps);
                 if(pad.get_direction() == N){currentPage = PAGE_2;}
                 if(pad.check_event(Gamepad::B_PRESSED) == true){
                     score++;
@@ -322,11 +302,10 @@
                 || (pad.check_event(Gamepad::Y_PRESSED) == true)){
                     currentPage = PAGE_4;
                 }
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_4:
                 lcd.clear();
-                
                 lcd.printString("Question 2",0,0);
                 lcd.printString("If the control",0,1);
                 lcd.printString("signal for",0,2);
@@ -336,11 +315,10 @@
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_5;}
                 if(pad.get_direction() == N){currentPage = PAGE_4;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_5:
                 lcd.clear();
-                
                 lcd.printString("t(on) = 70us",0,0);
                 lcd.printString("t(off) = 30us",0,1);
                 lcd.printString("what is the",0,2);
@@ -350,10 +328,9 @@
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_6;}
                 if(pad.get_direction() == N){currentPage = PAGE_4;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_6:
-                pad.init();
                 lcd.clear();
                 if(point > 1) {
                     lcd.printString("A. 10kHz",0,2);
@@ -369,7 +346,6 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, up);
                 lcd.refresh();
-                wait(2.0f/fps);
                 if(pad.get_direction() == N){currentPage = PAGE_5;}
                 if(pad.check_event(Gamepad::A_PRESSED) == true){
                     score++;
@@ -380,7 +356,7 @@
                 || (pad.check_event(Gamepad::X_PRESSED) == true)){
                     currentPage = PAGE_7;
                 }
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_7:
                 lcd.clear();
@@ -393,11 +369,10 @@
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_8;}
                 if(pad.get_direction() == N){currentPage = PAGE_7;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_8:
                 lcd.clear();
-                
                 lcd.printString("is the value",0,0);
                 lcd.printString("of x(-t+5) at",0,1);
                 lcd.printString("t=0?",0,2);
@@ -405,10 +380,9 @@
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_9;}
                 if(pad.get_direction() == N){currentPage = PAGE_7;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_9:
-                pad.init();
                 lcd.clear();
                 if(point > 2) {
                     lcd.printString("A. x(0)",0,2);
@@ -424,7 +398,6 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, up);
                 lcd.refresh();
-                wait(2.0f/fps);
                 if(pad.get_direction() == N){currentPage = PAGE_8;}
                 if(pad.check_event(Gamepad::Y_PRESSED) == true){
                     score++;
@@ -435,7 +408,7 @@
                 || (pad.check_event(Gamepad::X_PRESSED) == true)){
                     currentPage = PAGE_10;
                 }
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_10:
                 lcd.clear();
@@ -444,7 +417,7 @@
                 lcd.printString("PRESS START",0,5);
                 lcd.refresh();
                 if(pad.check_event(Gamepad::START_PRESSED) == true) {finished = true;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
         }
     }
@@ -476,7 +449,6 @@
         switch (currentPage) {
             case PAGE_1:
                 lcd.clear();
-                
                 if (point > 0){
                     lcd.printString("Question 1",0,0);
                     lcd.printString("The answer is",0,1);
@@ -489,13 +461,12 @@
                     lcd.printString("$%^&*$%^&*",0,3);
                 }
                 lcd.drawSprite(39, 44, 4, 7, down);
-                lcd.refresh();
+                wait(1.0f/fps);
                 if(pad.get_direction() == S){currentPage = PAGE_2;}
                 if(pad.get_direction() == N){currentPage = PAGE_1;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_2:
-                pad.init();
                 lcd.clear();
                 if (point > 0){
                     lcd.printString("A. ",0,2);
@@ -511,7 +482,6 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, up);
                 lcd.refresh();
-                wait(2.0f/fps);
                 if(pad.get_direction() == N){currentPage = PAGE_1;}
                 if(pad.check_event(Gamepad::A_PRESSED) == true){
                     score++;
@@ -522,10 +492,9 @@
                 || (pad.check_event(Gamepad::Y_PRESSED) == true)){
                     currentPage = PAGE_3;
                 }
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_3:
-                
                 lcd.clear();
                 if (point > 1){
                     lcd.printString("Question 2",0,0);
@@ -542,10 +511,9 @@
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_4;}
                 if(pad.get_direction() == N){currentPage = PAGE_3;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_4:
-                pad.init();
                 lcd.clear();
                 if (point > 1){
                     lcd.printString("A. ",0,2);
@@ -561,7 +529,6 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, up);
                 lcd.refresh();
-                wait(2.0f/fps);
                 if(pad.get_direction() == N){currentPage = PAGE_3;}
                 if(pad.check_event(Gamepad::B_PRESSED) == true){
                     score++;
@@ -572,10 +539,9 @@
                 || (pad.check_event(Gamepad::Y_PRESSED) == true)){
                     currentPage = PAGE_5;
                 }
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_5:
-                
                 lcd.clear();
                 if (point > 2){
                     lcd.printString("Question 3",0,0);
@@ -592,10 +558,9 @@
                 lcd.refresh();
                 if(pad.get_direction() == S){currentPage = PAGE_6;}
                 if(pad.get_direction() == N){currentPage = PAGE_5;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_6:
-                pad.init();
                 lcd.clear();
                 if (point > 2){
                     lcd.printString("A. ",0,2);
@@ -611,7 +576,6 @@
                 }
                 lcd.drawSprite(39, 0, 4, 7, up);
                 lcd.refresh();
-                wait(2.0f/fps);
                 if(pad.get_direction() == N){currentPage = PAGE_5;}
                 if(pad.check_event(Gamepad::Y_PRESSED) == true){
                     score++;
@@ -622,7 +586,7 @@
                 || (pad.check_event(Gamepad::B_PRESSED) == true)){
                     currentPage = PAGE_7;
                 }
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
             case PAGE_7:
                 
@@ -632,7 +596,7 @@
                 lcd.printString("PRESS START",0,5);
                 lcd.refresh();
                 if(pad.check_event(Gamepad::START_PRESSED) == true) {finished = true;}
-                wait(2.0f/fps);
+                wait(1.0f/fps);
             break;
         }
     }