Project Submission (late)
Dependencies: mbed
Menus/StartMenu.h@3:83e79d31930c, 2019-05-10 (annotated)
- Committer:
- el17tc
- Date:
- Fri May 10 14:52:28 2019 +0000
- Revision:
- 3:83e79d31930c
- Parent:
- 0:72f372170a73
final commit, API is added.; I'm not sure if there is a specific statement of academic integrity wanted but- I declare that this work is 100% my own, I have not plagiarised any work or attempted to fabricate any part of it for extra marks.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17tc | 0:72f372170a73 | 1 | #ifndef STARTMENU_H |
el17tc | 0:72f372170a73 | 2 | #define STARTMENU_H |
el17tc | 0:72f372170a73 | 3 | |
el17tc | 0:72f372170a73 | 4 | #include "Menus.h" |
el17tc | 0:72f372170a73 | 5 | |
el17tc | 0:72f372170a73 | 6 | |
el17tc | 0:72f372170a73 | 7 | // button which changes the size of the maze |
el17tc | 3:83e79d31930c | 8 | /** SizeButton Class |
el17tc | 3:83e79d31930c | 9 | * @brief Derived from Button. Allows the user to pick the size of Maze they wish to solve. |
el17tc | 3:83e79d31930c | 10 | * @brief Mazes can only be 12x12, 16x16 or 20x20. |
el17tc | 3:83e79d31930c | 11 | * @brief If enabled, the timer increases in length for larger mazes. |
el17tc | 3:83e79d31930c | 12 | */ |
el17tc | 0:72f372170a73 | 13 | class SizeButton : public Button { |
el17tc | 0:72f372170a73 | 14 | public: |
el17tc | 0:72f372170a73 | 15 | SizeButton() { |
el17tc | 0:72f372170a73 | 16 | x = 5; |
el17tc | 0:72f372170a73 | 17 | y = 16; |
el17tc | 0:72f372170a73 | 18 | } |
el17tc | 0:72f372170a73 | 19 | void virtual run() { |
el17tc | 0:72f372170a73 | 20 | if (mazeSize < 20) |
el17tc | 0:72f372170a73 | 21 | mazeSize += 4; |
el17tc | 0:72f372170a73 | 22 | printf("sizeButton pushed\n"); |
el17tc | 0:72f372170a73 | 23 | } |
el17tc | 0:72f372170a73 | 24 | void virtual runBack() { |
el17tc | 0:72f372170a73 | 25 | if (mazeSize > 12) |
el17tc | 0:72f372170a73 | 26 | mazeSize -= 4; |
el17tc | 0:72f372170a73 | 27 | printf("sizeButton decreasing\n"); |
el17tc | 0:72f372170a73 | 28 | } |
el17tc | 0:72f372170a73 | 29 | }; |
el17tc | 0:72f372170a73 | 30 | |
el17tc | 0:72f372170a73 | 31 | // button which toggles the timer on or off |
el17tc | 3:83e79d31930c | 32 | /** TimerButton Class |
el17tc | 3:83e79d31930c | 33 | * @brief Derived from Button. Toggles the timer on or off. |
el17tc | 3:83e79d31930c | 34 | * @brief If turned off, the timer will count up instead of down and there is no faliure state. |
el17tc | 3:83e79d31930c | 35 | * @brief I.e. the program will only end when the maze is finished. |
el17tc | 3:83e79d31930c | 36 | */ |
el17tc | 0:72f372170a73 | 37 | class TimerButton : public Button { |
el17tc | 0:72f372170a73 | 38 | public: |
el17tc | 0:72f372170a73 | 39 | TimerButton() { |
el17tc | 0:72f372170a73 | 40 | x = 5; |
el17tc | 0:72f372170a73 | 41 | y = 24; |
el17tc | 0:72f372170a73 | 42 | } |
el17tc | 0:72f372170a73 | 43 | void virtual run() { |
el17tc | 0:72f372170a73 | 44 | timerFlag = !timerFlag; |
el17tc | 0:72f372170a73 | 45 | printf("timerButton pushed\n"); |
el17tc | 0:72f372170a73 | 46 | } |
el17tc | 0:72f372170a73 | 47 | }; |
el17tc | 0:72f372170a73 | 48 | |
el17tc | 0:72f372170a73 | 49 | // button that triggers the main game loop |
el17tc | 3:83e79d31930c | 50 | /** PlayButton Class |
el17tc | 3:83e79d31930c | 51 | * @brief Derived from Buttons. Triggers the main game loop. |
el17tc | 3:83e79d31930c | 52 | */ |
el17tc | 0:72f372170a73 | 53 | class PlayButton : public Button { |
el17tc | 0:72f372170a73 | 54 | public: |
el17tc | 0:72f372170a73 | 55 | PlayButton() { |
el17tc | 0:72f372170a73 | 56 | x = 5; |
el17tc | 0:72f372170a73 | 57 | y = 40; |
el17tc | 0:72f372170a73 | 58 | } |
el17tc | 0:72f372170a73 | 59 | void virtual run() { |
el17tc | 0:72f372170a73 | 60 | printf("PlayButton pushed\n"); |
el17tc | 0:72f372170a73 | 61 | beginFlag = true; |
el17tc | 0:72f372170a73 | 62 | } |
el17tc | 0:72f372170a73 | 63 | }; |
el17tc | 0:72f372170a73 | 64 | |
el17tc | 0:72f372170a73 | 65 | |
el17tc | 0:72f372170a73 | 66 | // the StartMenu is the menu for game setup and starting the game. |
el17tc | 3:83e79d31930c | 67 | /** VictoryMenu Class |
el17tc | 3:83e79d31930c | 68 | * @brief Derived from Menu. Used to change the game's parameters of maze size and timer on or off. |
el17tc | 3:83e79d31930c | 69 | */ |
el17tc | 0:72f372170a73 | 70 | class StartMenu : public Menu { |
el17tc | 0:72f372170a73 | 71 | public: |
el17tc | 0:72f372170a73 | 72 | StartMenu(N5110* screenPtr) : Menu(screenPtr) { |
el17tc | 0:72f372170a73 | 73 | buttons[0] = new SizeButton; |
el17tc | 0:72f372170a73 | 74 | buttons[1] = new TimerButton; |
el17tc | 0:72f372170a73 | 75 | buttons[2] = new PlayButton; |
el17tc | 0:72f372170a73 | 76 | currentButton = buttons[0]; |
el17tc | 0:72f372170a73 | 77 | numOfButtons = 3; |
el17tc | 0:72f372170a73 | 78 | buttonIndex = 0; |
el17tc | 0:72f372170a73 | 79 | } |
el17tc | 0:72f372170a73 | 80 | void virtual draw() { |
el17tc | 0:72f372170a73 | 81 | std::stringstream ssize; |
el17tc | 0:72f372170a73 | 82 | ssize << "Size: " << mazeSize; |
el17tc | 0:72f372170a73 | 83 | std::string someString; |
el17tc | 0:72f372170a73 | 84 | if (timerFlag) |
el17tc | 0:72f372170a73 | 85 | someString = "Timer: YES"; |
el17tc | 0:72f372170a73 | 86 | else |
el17tc | 0:72f372170a73 | 87 | someString = "Timer: NO"; |
el17tc | 0:72f372170a73 | 88 | lcd->printString("Game params:",10,1); |
el17tc | 0:72f372170a73 | 89 | lcd->printString(ssize.str().c_str(),10,2); |
el17tc | 0:72f372170a73 | 90 | lcd->printString(someString.c_str(),10,3); |
el17tc | 0:72f372170a73 | 91 | lcd->printString("Play",10,5); |
el17tc | 0:72f372170a73 | 92 | } |
el17tc | 3:83e79d31930c | 93 | /** Destructor |
el17tc | 3:83e79d31930c | 94 | */ |
el17tc | 0:72f372170a73 | 95 | ~StartMenu() { |
el17tc | 0:72f372170a73 | 96 | delete buttons[0]; |
el17tc | 0:72f372170a73 | 97 | delete buttons[1]; |
el17tc | 0:72f372170a73 | 98 | } |
el17tc | 0:72f372170a73 | 99 | }; |
el17tc | 0:72f372170a73 | 100 | |
el17tc | 0:72f372170a73 | 101 | #endif // STARTMENU_H |