Mochu Yao explorer game
Dependencies: mbed
menu/Menu.h@30:65e639ace415, 2020-04-29 (annotated)
- Committer:
- el17my
- Date:
- Wed Apr 29 03:18:13 2020 +0000
- Revision:
- 30:65e639ace415
- Parent:
- 29:2d592452e3fb
- Child:
- 31:8e92b65e0779
4.29
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17my | 21:349c70c8a7de | 1 | #ifndef MENU_H |
el17my | 21:349c70c8a7de | 2 | #define MENU_H |
el17my | 21:349c70c8a7de | 3 | |
el17my | 21:349c70c8a7de | 4 | #include "mbed.h" |
el17my | 21:349c70c8a7de | 5 | #include "N5110.h" |
el17my | 21:349c70c8a7de | 6 | #include "Gamepad.h" |
el17my | 21:349c70c8a7de | 7 | #include "Gameengine.h" |
el17my | 27:354d91d59b6d | 8 | /** State for finite state machine struct */ |
el17my | 21:349c70c8a7de | 9 | struct State { |
el17my | 30:65e639ace415 | 10 | int output;/**< the output state. */ |
el17my | 30:65e639ace415 | 11 | float time;/**< wait time. */ |
el17my | 29:2d592452e3fb | 12 | int next_state[4];/**< the 4 state to change. */ |
el17my | 21:349c70c8a7de | 13 | }; |
el17my | 21:349c70c8a7de | 14 | |
el17my | 27:354d91d59b6d | 15 | /** Menu Class |
el17my | 27:354d91d59b6d | 16 | |
el17my | 27:354d91d59b6d | 17 | * @1 build three page to choose |
el17my | 27:354d91d59b6d | 18 | * @2 build a good welcome_page |
el17my | 27:354d91d59b6d | 19 | * @3 connect with the gamepad and makesure the game is working |
el17my | 27:354d91d59b6d | 20 | * @date April 27th 2020 |
el17my | 27:354d91d59b6d | 21 | * @author Yaomochu |
el17my | 27:354d91d59b6d | 22 | * @code |
el17my | 27:354d91d59b6d | 23 | |
el17my | 27:354d91d59b6d | 24 | #include "N5110.h" |
el17my | 27:354d91d59b6d | 25 | #include "Gamepad.h" |
el17my | 27:354d91d59b6d | 26 | #include "mbed.h" |
el17my | 27:354d91d59b6d | 27 | #include "menu.h" |
el17my | 27:354d91d59b6d | 28 | |
el17my | 27:354d91d59b6d | 29 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
el17my | 27:354d91d59b6d | 30 | Gamepad gamepad; |
el17my | 27:354d91d59b6d | 31 | menu _menu; |
el17my | 27:354d91d59b6d | 32 | |
el17my | 27:354d91d59b6d | 33 | int main() { |
el17my | 27:354d91d59b6d | 34 | gamepad.init(); |
el17my | 27:354d91d59b6d | 35 | _menu.init(); |
el17my | 27:354d91d59b6d | 36 | lcd.init(); |
el17my | 27:354d91d59b6d | 37 | lcd.normalMode(); |
el17my | 27:354d91d59b6d | 38 | lcd.setBrightness(0.5); |
el17my | 27:354d91d59b6d | 39 | while(1) { |
el17my | 27:354d91d59b6d | 40 | |
el17my | 27:354d91d59b6d | 41 | // clear, refresh lcd and run the menu. |
el17my | 27:354d91d59b6d | 42 | lcd.clear(); |
el17my | 27:354d91d59b6d | 43 | _menu.run_engine(lcd, gamepad); |
el17my | 27:354d91d59b6d | 44 | lcd.refresh(); |
el17my | 27:354d91d59b6d | 45 | wait(0.01); |
el17my | 27:354d91d59b6d | 46 | } |
el17my | 27:354d91d59b6d | 47 | } |
el17my | 27:354d91d59b6d | 48 | |
el17my | 27:354d91d59b6d | 49 | *@endcode |
el17my | 26:4d193529b447 | 50 | */ |
el17my | 21:349c70c8a7de | 51 | |
el17my | 21:349c70c8a7de | 52 | |
el17my | 21:349c70c8a7de | 53 | class Menu { |
el17my | 21:349c70c8a7de | 54 | public: |
el17my | 27:354d91d59b6d | 55 | // Constructor and Destructor. |
el17my | 27:354d91d59b6d | 56 | /** |
el17my | 27:354d91d59b6d | 57 | * @brief Constructor @details Non user specified. |
el17my | 27:354d91d59b6d | 58 | */ |
el17my | 27:354d91d59b6d | 59 | Menu(); |
el17my | 27:354d91d59b6d | 60 | /** |
el17my | 27:354d91d59b6d | 61 | * @brief Destructor @details Non user specified. |
el17my | 27:354d91d59b6d | 62 | */ |
el17my | 27:354d91d59b6d | 63 | ~Menu(); |
el17my | 27:354d91d59b6d | 64 | // Mutators |
el17my | 27:354d91d59b6d | 65 | /** |
el17my | 27:354d91d59b6d | 66 | * @brief Initialises the Menu. |
el17my | 27:354d91d59b6d | 67 | */ |
el17my | 27:354d91d59b6d | 68 | void init(); |
el17my | 27:354d91d59b6d | 69 | /** |
el17my | 27:354d91d59b6d | 70 | * @brief Runs the menu and a state machine. |
el17my | 27:354d91d59b6d | 71 | * @param &lcd @details The lcd object from the N5110 class |
el17my | 27:354d91d59b6d | 72 | * @param &gamepad @details The gamepad object from Gamepad class |
el17my | 27:354d91d59b6d | 73 | */ |
el17my | 27:354d91d59b6d | 74 | void run_engine(N5110 &lcd, Gamepad &gamepad); |
el17my | 27:354d91d59b6d | 75 | |
el17my | 22:f8ba0ab7465c | 76 | |
el17my | 22:f8ba0ab7465c | 77 | |
el17my | 22:f8ba0ab7465c | 78 | private: |
el17my | 27:354d91d59b6d | 79 | void run_game(N5110 &lcd, Gamepad &gamepad); |
el17my | 21:349c70c8a7de | 80 | void display_page1(N5110 &lcd, Gamepad &gamepad); |
el17my | 21:349c70c8a7de | 81 | void display_page2(N5110 &lcd, Gamepad &gamepad); |
el17my | 22:f8ba0ab7465c | 82 | void get_output(N5110 &lcd, Gamepad &gamepad); |
el17my | 21:349c70c8a7de | 83 | void get_input(bool start, bool back, bool b); |
el17my | 21:349c70c8a7de | 84 | Gameengine _game_engine; |
el17my | 21:349c70c8a7de | 85 | int _input_value; |
el17my | 21:349c70c8a7de | 86 | int _output; |
el17my | 21:349c70c8a7de | 87 | int _state; |
el17my | 21:349c70c8a7de | 88 | }; |
el17my | 21:349c70c8a7de | 89 | #endif |
el17my | 21:349c70c8a7de | 90 | |
el17my | 21:349c70c8a7de | 91 |