QuickClick, a reaction timing game which allows single and multiplayer mode.

Dependencies:   Controller Display N5110 Operator mbed

Revision:
7:365bd984c68e
Parent:
6:e7510e120617
Child:
8:22abb23cd8af
--- a/main.cpp	Sun Apr 16 13:45:27 2017 +0000
+++ b/main.cpp	Sun Apr 16 19:40:26 2017 +0000
@@ -6,33 +6,32 @@
 
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); 
 Display display; 
-Controller pad; 
+Controller ctrl; 
 Operator Opp; 
 int button_val;
 int instruction_val;
 void starter();
 
 int main() {
-    button_val=0;
-    lcd.init();  
-    Opp.init();
-    display.init(); 
-    pad.init(); 
-    starter(); 
+    button_val=0;       //(All classes are initialised here variables are set to 
+    lcd.init();         //their default states the lcd and controller are configured                                                                          
+    display.init();     //        
+    ctrl.init();        //)
+    starter();          //Methord describing starting screen when the controller is first booted up
         while(1) {
-            instruction_val = Opp.random_instruction(display, lcd); 
+            ctrl.ledsOFF(); 
+            instruction_val = Opp.random_instruction(display, lcd);     //sets instruction_val as the random instruction from display 
             printf("MAIN instruction_val = %d\n", instruction_val); 
-            display.drawCircle(pad, lcd);  
-            button_val = pad.check_for_buttons(); 
-            printf("MAIN button_val = %d\n", button_val); 
-            pad.ledsOFF();  
-            if (button_val == instruction_val) {
-                Opp.Correct(pad);
-            } else {
-                pad.init();
-                Opp.Game_Over(pad, lcd); 
-                display.init();
-                starter(); 
+            display.drawCircle(ctrl, lcd);                               //Draws circle, displays instruction and allows the circle to be drawn faster with time
+            button_val = ctrl.check_for_buttons();                       //sets button_val as the instruction performed by the user
+            printf("MAIN button_val = %d\n", button_val);    
+            if (button_val == instruction_val) {                        //if the user performs the instruction correctly perform:
+                Opp.Correct(ctrl); 
+            } else {                                                    //otherwise the user has performed the instruction incorrectly so perform:
+                ctrl.init();                                            //reset flags 
+                Opp.Game_Over(ctrl, lcd);                                //display score and level 
+                display.init();                                         //reset waiting time
+                starter();                                              //go back to starter screen
         }
     }
     
@@ -40,15 +39,16 @@
 
 void starter() {
   
-    lcd.clear();
-    lcd.printString("Quick Click",10,1);  
-    lcd.printString("Start >",24,4);
+    lcd.clear();                                                            
+    lcd.printString("Quick Click",10,0);                                  //text to be displayed when on starter screen
+    lcd.printString("Start >",24,5);
     lcd.refresh();
 
-    while (pad.check_event(Controller::START_PRESSED) == false) {
-        pad.ledsON();
+    while (ctrl.check_event(Controller::START_PRESSED) == false) {       //whilst the start button hasn't been pressed just flash the leds and nothing else
+        ctrl.ledsON();                                                    
         wait(0.1);
-        pad.ledsOFF();
+        ctrl.ledsOFF();
         wait(0.1);
     }
-}   
\ No newline at end of file
+} 
+    
\ No newline at end of file