Project Submission (late)
Dependencies: mbed
Menus/MainMenu.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 MAINMENU_H |
el17tc | 0:72f372170a73 | 2 | #define MAINMENU_H |
el17tc | 0:72f372170a73 | 3 | |
el17tc | 0:72f372170a73 | 4 | #include "StartMenu.h" |
el17tc | 0:72f372170a73 | 5 | #include "OptionsMenu.h" |
el17tc | 0:72f372170a73 | 6 | #include "MenuGraphics.h" |
el17tc | 0:72f372170a73 | 7 | // StartButton takes you to the start menu screen. |
el17tc | 3:83e79d31930c | 8 | /** StartButton Class |
el17tc | 3:83e79d31930c | 9 | * @brief Derived from Button. Takes you to the StartMenu screen where game params are set. |
el17tc | 3:83e79d31930c | 10 | */ |
el17tc | 0:72f372170a73 | 11 | class StartButton : public Button { |
el17tc | 0:72f372170a73 | 12 | public: |
el17tc | 0:72f372170a73 | 13 | N5110* lcd; |
el17tc | 0:72f372170a73 | 14 | StartButton(N5110* screenPtr) : lcd(screenPtr) { |
el17tc | 0:72f372170a73 | 15 | printf("StartButton constructor\n"); |
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 | printf("StartButton\n"); |
el17tc | 0:72f372170a73 | 21 | delete currentMenu; // free the previous memory assigned to the pointer |
el17tc | 0:72f372170a73 | 22 | currentMenu = new StartMenu(lcd); // assign the new (next) menu to it |
el17tc | 0:72f372170a73 | 23 | } |
el17tc | 0:72f372170a73 | 24 | }; |
el17tc | 0:72f372170a73 | 25 | |
el17tc | 0:72f372170a73 | 26 | // OptionsButton takes you to the game's options. |
el17tc | 3:83e79d31930c | 27 | /** OptionsButton Class |
el17tc | 3:83e79d31930c | 28 | * @brief Derived from Button. Takes you to the options menu. |
el17tc | 3:83e79d31930c | 29 | */ |
el17tc | 0:72f372170a73 | 30 | class OptionsButton : public Button { |
el17tc | 0:72f372170a73 | 31 | public: |
el17tc | 0:72f372170a73 | 32 | N5110* lcd; |
el17tc | 0:72f372170a73 | 33 | OptionsButton(N5110* screenPtr) : lcd(screenPtr) { |
el17tc | 0:72f372170a73 | 34 | printf("OptionsButton constructor\n"); |
el17tc | 0:72f372170a73 | 35 | x = 5; |
el17tc | 0:72f372170a73 | 36 | y = 24; |
el17tc | 0:72f372170a73 | 37 | } |
el17tc | 0:72f372170a73 | 38 | void virtual run() { |
el17tc | 0:72f372170a73 | 39 | printf("OptionsButton\n"); |
el17tc | 0:72f372170a73 | 40 | delete currentMenu; // free the previous memory assigned to the pointer |
el17tc | 0:72f372170a73 | 41 | currentMenu = new OptionsMenu(lcd); // assign the new (next) menu to it |
el17tc | 0:72f372170a73 | 42 | } |
el17tc | 0:72f372170a73 | 43 | }; |
el17tc | 0:72f372170a73 | 44 | |
el17tc | 0:72f372170a73 | 45 | // The MainMenu is the first menu displayed. |
el17tc | 0:72f372170a73 | 46 | // It has only two buttons because I did not have time for a leaderboard |
el17tc | 3:83e79d31930c | 47 | /** MainMenu Class |
el17tc | 3:83e79d31930c | 48 | * @brief Derived from Menu. MainMenu is the first menu displayed and serves as the start of the program loop. |
el17tc | 3:83e79d31930c | 49 | */ |
el17tc | 0:72f372170a73 | 50 | class MainMenu : public Menu { |
el17tc | 0:72f372170a73 | 51 | public: |
el17tc | 0:72f372170a73 | 52 | //Button* buttons[2]; |
el17tc | 0:72f372170a73 | 53 | MainMenu(N5110* screenPtr) : Menu(screenPtr) { |
el17tc | 0:72f372170a73 | 54 | buttons[0] = new StartButton(lcd); |
el17tc | 0:72f372170a73 | 55 | buttons[1] = new OptionsButton(lcd); |
el17tc | 0:72f372170a73 | 56 | currentButton = buttons[0]; |
el17tc | 0:72f372170a73 | 57 | numOfButtons = 2; |
el17tc | 0:72f372170a73 | 58 | buttonIndex = 0; |
el17tc | 0:72f372170a73 | 59 | } |
el17tc | 0:72f372170a73 | 60 | void virtual draw() { |
el17tc | 0:72f372170a73 | 61 | lcd->drawSprite(20,1,12,44,(int *)menuGraphic); |
el17tc | 0:72f372170a73 | 62 | lcd->printString("Start",10,2); |
el17tc | 0:72f372170a73 | 63 | lcd->printString("Options",10,3); |
el17tc | 0:72f372170a73 | 64 | } |
el17tc | 3:83e79d31930c | 65 | /** Destructor |
el17tc | 3:83e79d31930c | 66 | */ |
el17tc | 0:72f372170a73 | 67 | ~MainMenu() { |
el17tc | 0:72f372170a73 | 68 | delete buttons[0]; |
el17tc | 0:72f372170a73 | 69 | delete buttons[1]; |
el17tc | 0:72f372170a73 | 70 | } |
el17tc | 0:72f372170a73 | 71 | }; |
el17tc | 0:72f372170a73 | 72 | |
el17tc | 0:72f372170a73 | 73 | #endif // MAINMENU_H |