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:
15:a65444eb1194
Parent:
13:02002658e718
Child:
21:704d938acf5d
--- a/main.cpp	Thu Apr 18 04:53:04 2019 +0000
+++ b/main.cpp	Sat Apr 20 11:53:09 2019 +0000
@@ -14,6 +14,7 @@
 #include "Score.h"
 #include "Start.h"
 #include "Game_one.h"
+#include "Game_two.h"
 #include "Exam.h"
 #include "FXOS8700CQ.h"
 
@@ -23,9 +24,10 @@
 Score music;
 Start start;
 Game_one game_1;
+Game_two game_2;
 Exam test;
 // I2C connection for FXOS8700CQ accelerometer/magnetometer
-I2C fxos8700cq(I2C_SDA,I2C_SCL);  // PTE25/PTE24
+FXOS8700CQ device(I2C_SDA,I2C_SCL);  // PTE25/PTE24
 
 ///////////// prototypes ///////////////
 void init();
@@ -66,6 +68,9 @@
 int game_1_speed = 0;
 int game_1_cha = 0;
 int game_1_r = 1;
+int game_2_speed = 0;
+int game_2_cha = 0;
+int game_2_r = 1;
 int select = 0;
 int year = 0;
 int pass = 0;
@@ -92,7 +97,7 @@
         
         case MENU:
             //1. Display starting menu
-            //2. If Start is selected, initiate game
+            //2. If Start is selected, initiate year 1 game state
             //3. If Instruction is selected, give instruction
             int op = menu();
             if (op == 1){currentState = INSTRUCTION;}
@@ -102,12 +107,16 @@
                     switch (currentGame) {
                         case YEAR_1:
                             // 1. Initiate year 1 screen
-                            // 2. Choosing starter pokemon to start the mini game
+                            // 2. Set up the parameters for year 1
                             year_one();
                             year_one_set();
                             currentGame = STARTER;
                         break;
+                        
                         case STARTER:
+                            // 1. Provide selection screen for starter pokemon to select which mini game to initiate
+                            // 2. Provide description for the mini game and pokemon
+                            // 3. Initiate the mini game according to the pokemon being selected
                             select = 0;
                             start.init(pad);
                             start.starter_draw(lcd);
@@ -159,20 +168,26 @@
                                 }
                                 currentGame = CHARMANDER;}
                         break;
+                        
+                        // Game loop for Bulbasaur's mini game
                         case BULBASAUR:
                             score = 3;
                             currentGame = EXAM;
                         break;
+                        
+                        // Game loop for Squirtle's mini game
                         case SQUIRTLE:
                             int i = 0;
                             score = 0;
                             while(i < 3){
+                                // Indicate for which term the current game is in
                                 if(i == 0) {term_one();}
                                 else if(i == 1) {term_two();}
                                 else{term_three();}
                                 game_1.init(game_1_speed, game_1_cha, game_1_r);
                                 int j = 0;
                                 while(j < 10){
+                                    // Game loop for 10 rounds
                                     game_1.read_input(pad);
                                     game_1.update(pad, lcd);
                                     game_1.render(lcd, game_1_cha);
@@ -180,6 +195,7 @@
                                     j = game_1.get_count();
                                 }
                                 i = i++;
+                                // determine if win condition is met, return score to proceed to EXAM game loop
                                 if(game_1.print_scores(lcd) >= 8) {
                                     win();
                                     music.win(pad);
@@ -197,10 +213,43 @@
                             currentGame = EXAM;
                             
                         break;
+                        
+                        // Game loop for Charmander's mini game
                         case CHARMANDER:
-                            score = 2;
+                            i = 0;
+                            score = 0;
+                            while (i < 3) {
+                                if(i == 0) {term_one();}
+                                else if(i == 1) {term_two();}
+                                else{term_three();}
+                                game_2.init(game_2_speed, game_2_cha, game_2_r);
+                                int j = 0;
+                                while(j < 10){
+                                    game_2.read_input(device);
+                                    game_2.update(pad, lcd, game_2_cha);
+                                    game_2.render(lcd, game_2_cha);
+                                    wait(1.0f/fps);
+                                    j = game_2.get_count();
+                                }
+                                i = i++;
+                                if(game_2.get_count() == 10) {
+                                    win();
+                                    music.win(pad);
+                                    wait(0.5);
+                                    score++;
+                                }
+                                else {
+                                    lose();
+                                    pad.tone(750.0,0.2);
+                                    wait(0.5);
+                                    pad.tone(750.0,0.2);
+                                    wait(1.0);
+                                }
+                            }
                             currentGame = EXAM;
                         break;
+                        
+                        // Game loop for EXAM
                         case EXAM:
                             test.exam_title(pad, lcd);
                             if(year == 0) {pass = test.exam_q_one(pad, lcd, score);}
@@ -259,7 +308,8 @@
                                     lcd.refresh();
                                     wait(0.3);
                                 }
-                                currentGame = BULBASAUR;}
+                                currentGame = BULBASAUR;
+                            }
                             else if(select == 2){
                                 music.evolution_music(pad, lcd, select, year);
                                 while(pad.check_event(Gamepad::A_PRESSED) == false){
@@ -270,7 +320,8 @@
                                     lcd.refresh();
                                     wait(0.3);
                                 }
-                                currentGame = CHARMANDER;}
+                                currentGame = CHARMANDER;
+                            }
                         break;
                         case YEAR_3:
                             year_three();
@@ -297,7 +348,8 @@
                                     lcd.refresh();
                                     wait(0.3);
                                 }
-                                currentGame = BULBASAUR;}
+                                currentGame = BULBASAUR;
+                            }
                             else if(select == 2){
                                 music.evolution_music(pad, lcd, select, year);
                                 while(pad.check_event(Gamepad::A_PRESSED) == false){
@@ -308,7 +360,8 @@
                                     lcd.refresh();
                                     wait(0.3);
                                 }
-                                currentGame = CHARMANDER;}
+                                currentGame = CHARMANDER;
+                            }
                         break;
                         case GRADUATION:
                             lcd.clear();
@@ -515,6 +568,9 @@
     game_1_speed = 9;
     game_1_cha = 1;
     game_1_r = 5;
+    game_2_speed = 5;
+    game_2_cha = 1;
+    game_2_r = 6;
 }
 
 void year_two()
@@ -565,6 +621,9 @@
     game_1_speed = 12;
     game_1_cha = 2;
     game_1_r = 3;
+    game_2_speed = 6;
+    game_2_cha = 2;
+    game_2_r = 5;
 }
 
 void year_three()
@@ -615,6 +674,9 @@
     game_1_speed = 14;
     game_1_cha = 3;
     game_1_r = 2;
+    game_2_speed = 7;
+    game_2_cha = 3;
+    game_2_r = 3;
 }
 
 void instruction()