Project Submission (late)
Dependencies: mbed
Menus/MainMenu.h@0:72f372170a73, 2019-05-10 (annotated)
- Committer:
- el17tc
- Date:
- Fri May 10 08:07:10 2019 +0000
- Revision:
- 0:72f372170a73
- Child:
- 3:83e79d31930c
Save at functioning version;
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 | 0:72f372170a73 | 8 | class StartButton : public Button { |
el17tc | 0:72f372170a73 | 9 | public: |
el17tc | 0:72f372170a73 | 10 | N5110* lcd; |
el17tc | 0:72f372170a73 | 11 | StartButton(N5110* screenPtr) : lcd(screenPtr) { |
el17tc | 0:72f372170a73 | 12 | printf("StartButton constructor\n"); |
el17tc | 0:72f372170a73 | 13 | x = 5; |
el17tc | 0:72f372170a73 | 14 | y = 16; |
el17tc | 0:72f372170a73 | 15 | } |
el17tc | 0:72f372170a73 | 16 | void virtual run() { |
el17tc | 0:72f372170a73 | 17 | printf("StartButton\n"); |
el17tc | 0:72f372170a73 | 18 | delete currentMenu; // free the previous memory assigned to the pointer |
el17tc | 0:72f372170a73 | 19 | currentMenu = new StartMenu(lcd); // assign the new (next) menu to it |
el17tc | 0:72f372170a73 | 20 | } |
el17tc | 0:72f372170a73 | 21 | }; |
el17tc | 0:72f372170a73 | 22 | |
el17tc | 0:72f372170a73 | 23 | // OptionsButton takes you to the game's options. |
el17tc | 0:72f372170a73 | 24 | class OptionsButton : public Button { |
el17tc | 0:72f372170a73 | 25 | public: |
el17tc | 0:72f372170a73 | 26 | N5110* lcd; |
el17tc | 0:72f372170a73 | 27 | OptionsButton(N5110* screenPtr) : lcd(screenPtr) { |
el17tc | 0:72f372170a73 | 28 | printf("OptionsButton constructor\n"); |
el17tc | 0:72f372170a73 | 29 | x = 5; |
el17tc | 0:72f372170a73 | 30 | y = 24; |
el17tc | 0:72f372170a73 | 31 | } |
el17tc | 0:72f372170a73 | 32 | void virtual run() { |
el17tc | 0:72f372170a73 | 33 | printf("OptionsButton\n"); |
el17tc | 0:72f372170a73 | 34 | delete currentMenu; // free the previous memory assigned to the pointer |
el17tc | 0:72f372170a73 | 35 | currentMenu = new OptionsMenu(lcd); // assign the new (next) menu to it |
el17tc | 0:72f372170a73 | 36 | } |
el17tc | 0:72f372170a73 | 37 | }; |
el17tc | 0:72f372170a73 | 38 | |
el17tc | 0:72f372170a73 | 39 | // The MainMenu is the first menu displayed. |
el17tc | 0:72f372170a73 | 40 | // It has only two buttons because I did not have time for a leaderboard |
el17tc | 0:72f372170a73 | 41 | class MainMenu : public Menu { |
el17tc | 0:72f372170a73 | 42 | public: |
el17tc | 0:72f372170a73 | 43 | //Button* buttons[2]; |
el17tc | 0:72f372170a73 | 44 | MainMenu(N5110* screenPtr) : Menu(screenPtr) { |
el17tc | 0:72f372170a73 | 45 | buttons[0] = new StartButton(lcd); |
el17tc | 0:72f372170a73 | 46 | buttons[1] = new OptionsButton(lcd); |
el17tc | 0:72f372170a73 | 47 | currentButton = buttons[0]; |
el17tc | 0:72f372170a73 | 48 | numOfButtons = 2; |
el17tc | 0:72f372170a73 | 49 | buttonIndex = 0; |
el17tc | 0:72f372170a73 | 50 | } |
el17tc | 0:72f372170a73 | 51 | void virtual draw() { |
el17tc | 0:72f372170a73 | 52 | lcd->drawSprite(20,1,12,44,(int *)menuGraphic); |
el17tc | 0:72f372170a73 | 53 | lcd->printString("Start",10,2); |
el17tc | 0:72f372170a73 | 54 | lcd->printString("Options",10,3); |
el17tc | 0:72f372170a73 | 55 | } |
el17tc | 0:72f372170a73 | 56 | ~MainMenu() { |
el17tc | 0:72f372170a73 | 57 | delete buttons[0]; |
el17tc | 0:72f372170a73 | 58 | delete buttons[1]; |
el17tc | 0:72f372170a73 | 59 | } |
el17tc | 0:72f372170a73 | 60 | }; |
el17tc | 0:72f372170a73 | 61 | |
el17tc | 0:72f372170a73 | 62 | #endif // MAINMENU_H |