Max Houghton
/
MazeGame_el15mh
el15mh 200929957
main.cpp
- Committer:
- el15mh
- Date:
- 2017-03-30
- Revision:
- 2:a488caea1601
- Parent:
- 1:8ce2586b5965
- Child:
- 3:02653cb1c8f8
File content as of revision 2:a488caea1601:
#include "mbed.h" #include "N5110.h" #include "Gamepad.h" // CREATE OBJECTS // N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad pad; // FUNCTION PROTOTYPES // void init(); void difficultyOptions(); void colourOptions(); int main() { init(); // initialise devices printf("Devices initialised \n"); int selected = 0; while(1) { // printf("While loop 1 \n"); // printf("Selected = %i \n", selected); switch (selected) { case 1: lcd.clear(); // displays options page with indicator on first lcd.printString("Game Options:", 0, 0); lcd.printString(">Difficulty", 0, 2); lcd.printString(" Ball Colour", 0, 3); lcd.refresh(); if (pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)){ difficultyOptions(); } wait_ms(250); break; case 2: lcd.clear(); // displays options page with indicator on second lcd.printString("Game Options:", 0, 0); lcd.printString(" Difficulty", 0, 2); lcd.printString(">Ball Colour", 0, 3); lcd.refresh(); // if second option selected if (pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)){ colourOptions(); } wait_ms(250); break; default: selected = 1; break; } char d = pad.get_direction(); if ((d == NW) || (d == N) || (d == NE)){ selected -= 1; } if ((d == SW) || (d == S) || (d == SE)){ selected += 1; } if (pad.check_event(Gamepad::Y_PRESSED)){ selected -= 1; } if (pad.check_event(Gamepad::X_PRESSED)){ selected += 1; } } } void init() { lcd.init(); pad.init(); } void difficultyOptions() { int selected = 0; int exit = 0; while(exit == 0){ switch(selected){ case 1: lcd.clear(); lcd.printString("Difficulty: ", 0, 0); lcd.printString(">Easy", 0, 2); lcd.printString(" Hard", 0, 3); lcd.refresh(); if (pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)){ // maze.mazeIndex = 0; lcd.clear(); lcd.printString("Easy mode", 0, 1); lcd.refresh(); wait(2); } break; case 2: lcd.clear(); lcd.printString("Difficulty: ", 0, 0); lcd.printString(" Easy", 0, 2); lcd.printString(">Hard", 0, 3); lcd.refresh(); if (pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)){ // maze.mazeIndex = 1; lcd.clear(); lcd.printString("Hard mode", 0, 1); lcd.refresh(); wait(2); } break; default: selected = 1; break; } char d = pad.get_direction(); if ((d == NW) || (d == N) || (d == NE)){ selected -= 1; } if ((d == SW) || (d == S) || (d == SE)){ selected += 1; } if (pad.check_event(Gamepad::BACK_PRESSED)){ exit = 1; } } } void colourOptions() { int selected = 0; int exit = 0; while(exit == 0){ switch(selected){ case 1: printf("case 2.1"); lcd.clear(); lcd.printString("Ball colour: ", 0, 0); lcd.printString(">Transparent", 0, 2); lcd.printString(" Solid", 0, 3); lcd.refresh(); if (pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)){ // ball.ballColour = 0; lcd.clear(); lcd.printString("Transparent", 0, 1); lcd.refresh(); wait(2); } break; case 2: printf("case 2.2"); lcd.clear(); lcd.printString("Ball colour: ", 0, 0); lcd.printString(" Transparent", 0, 2); lcd.printString(">Solid", 0, 3); lcd.refresh(); if (pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::JOY_PRESSED)){ // ball.ballColour = 1; lcd.clear(); lcd.printString("Solid", 0, 1); lcd.refresh(); wait(2); } break; default: selected = 1; break; } char d = pad.get_direction(); if ((d == NW) || (d == N) || (d == NE)){ selected -= 1; } if ((d == SW) || (d == S) || (d == SE)){ selected += 1; } if (pad.check_event(Gamepad::BACK_PRESSED)){ exit = 1; } } }