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