QuickClick, a reaction timing game which allows single and multiplayer mode.
Dependencies: Controller Display N5110 Operator mbed
main.cpp
- Committer:
- domkay97
- Date:
- 2017-04-16
- Revision:
- 8:22abb23cd8af
- Parent:
- 7:365bd984c68e
- Child:
- 9:7237faca8baa
File content as of revision 8:22abb23cd8af:
#include "mbed.h" #include "N5110.h" #include "Display.h" #include "Controller.h" #include "Operator.h" N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Display display; Controller ctrl; Operator Opp; int button_val; int instruction_val; void starter(); int main() { 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) { 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(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 } } } void starter() { int players = 1; lcd.clear(); lcd.printString("Quick Click",10,0); ; lcd.printString("Players = ",10,2); lcd.refresh(); while (ctrl.check_event(Controller::JOY_PRESSED) == false) { float flicked = ctrl.get_joy(); if (flicked > 1) { players--;} if (flicked < -0.5) { players++;} if (players < 1) { players = 1;} char buffer[14]; sprintf(buffer,"0%d",players); lcd.printString(buffer,40,3); lcd.refresh(); wait(0.2); } lcd.clear(); lcd.printString("Quick Click",10,0); //text to be displayed when on starter screen lcd.printString("Start >",24,5); lcd.refresh(); 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); ctrl.ledsOFF(); wait(0.1); } }