Project Submission (late)

Dependencies:   mbed

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?

UserRevisionLine numberNew contents of line
el17tc 0:72f372170a73 1 #ifndef MENUS_H
el17tc 0:72f372170a73 2 #define MENUS_H
el17tc 0:72f372170a73 3
el17tc 0:72f372170a73 4 #include <string>
el17tc 0:72f372170a73 5 #include <sstream>
el17tc 0:72f372170a73 6
el17tc 0:72f372170a73 7 #include "N5110.h"
el17tc 0:72f372170a73 8
el17tc 0:72f372170a73 9 /* because these classes are so short and so closely linked, they are declared
el17tc 0:72f372170a73 10 and defined in the same files for convenience and clarity */
el17tc 0:72f372170a73 11
el17tc 3:83e79d31930c 12 /** Button Class
el17tc 3:83e79d31930c 13 * @brief An abstract class for all button's in the program
el17tc 3:83e79d31930c 14 * @brief The intent was to take advantage of polymorphism in C++ to cut out some large if-else blocks.
el17tc 3:83e79d31930c 15 * @brief There are two functions to overload, run() is always overloaded.
el17tc 3:83e79d31930c 16 * @brief runBack() is only overloaded for buttons attributed to increasing and decreasing variables,
el17tc 3:83e79d31930c 17 * @brief for example buttons to modify the maze size or contrast/brightness.
el17tc 3:83e79d31930c 18 *
el17tc 3:83e79d31930c 19 * @brief Version 1.0
el17tc 3:83e79d31930c 20 * @author Thomas Caine
el17tc 3:83e79d31930c 21 * @date May 2019
el17tc 3:83e79d31930c 22 */
el17tc 0:72f372170a73 23 class Button {
el17tc 0:72f372170a73 24 public:
el17tc 0:72f372170a73 25 int x;
el17tc 0:72f372170a73 26 int y;
el17tc 3:83e79d31930c 27 /** Button default constructor
el17tc 3:83e79d31930c 28 */
el17tc 0:72f372170a73 29 Button() {
el17tc 0:72f372170a73 30 x = y = 0;
el17tc 0:72f372170a73 31 }
el17tc 3:83e79d31930c 32 /** virtual run function for polymorphism
el17tc 3:83e79d31930c 33 */
el17tc 0:72f372170a73 34 void virtual run() {
el17tc 0:72f372170a73 35 printf("Button\n");
el17tc 0:72f372170a73 36 }
el17tc 3:83e79d31930c 37 /** virtual runBack function for polymorphism
el17tc 3:83e79d31930c 38 */
el17tc 0:72f372170a73 39 void virtual runBack() {
el17tc 0:72f372170a73 40 printf("Back functionality\n");
el17tc 0:72f372170a73 41 // only overridden in functions that can be pressed backwards e.g. sliders
el17tc 0:72f372170a73 42 // for contrast and brightness
el17tc 0:72f372170a73 43 }
el17tc 0:72f372170a73 44 };
el17tc 0:72f372170a73 45
el17tc 3:83e79d31930c 46 /** Menu Class
el17tc 3:83e79d31930c 47 * @brief An abstract class for all Menus's in the program
el17tc 3:83e79d31930c 48 * @brief Takes advantage of polymorphism. Draw() function is overriden in every inheriting Menu class.
el17tc 3:83e79d31930c 49 * @brief Score is used in the VictoryMenu and DefeatMenu classes.
el17tc 3:83e79d31930c 50 * @details Due to the similarity of Menu classes and their small size, I did not give them all header and source files.
el17tc 3:83e79d31930c 51 * @details Instead, classes are defined when they are declared in the same file and Buttons and Menus are grouped
el17tc 3:83e79d31930c 52 * @details into the same header files based on common functionality.
el17tc 3:83e79d31930c 53 *
el17tc 3:83e79d31930c 54 * @brief Version 1.0
el17tc 3:83e79d31930c 55 * @author Thomas Caine
el17tc 3:83e79d31930c 56 * @date May 2019
el17tc 3:83e79d31930c 57 */
el17tc 0:72f372170a73 58 class Menu {
el17tc 0:72f372170a73 59 public:
el17tc 0:72f372170a73 60 Button* buttons[3];
el17tc 0:72f372170a73 61 int score; // used in the victory and defeat menus
el17tc 0:72f372170a73 62 int numOfButtons;
el17tc 0:72f372170a73 63 int buttonIndex;
el17tc 0:72f372170a73 64 N5110* lcd;
el17tc 3:83e79d31930c 65 /** Constructor for the Menu base class.
el17tc 3:83e79d31930c 66 * @param lcd pointer - Passed to every menu object (derived classes super this constructor) so they can print to the lcd
el17tc 3:83e79d31930c 67 */
el17tc 0:72f372170a73 68 Menu(N5110* screenPtr) : lcd(screenPtr) {
el17tc 0:72f372170a73 69 numOfButtons = buttonIndex = 0;
el17tc 0:72f372170a73 70 }
el17tc 3:83e79d31930c 71 /** Virtual draw function, overloaded by Menus to print unique stuff.
el17tc 3:83e79d31930c 72 */
el17tc 0:72f372170a73 73 void virtual draw() {
el17tc 0:72f372170a73 74 printf("This is a menu\n");
el17tc 0:72f372170a73 75 }
el17tc 0:72f372170a73 76 };
el17tc 0:72f372170a73 77
el17tc 0:72f372170a73 78 // important flags used throughout the menus to interact with the game's settings
el17tc 0:72f372170a73 79 Menu *currentMenu;
el17tc 0:72f372170a73 80 Button *currentButton;
el17tc 0:72f372170a73 81 double contrastVal = 0.5;
el17tc 0:72f372170a73 82 double brightnessVal = 0.5;
el17tc 0:72f372170a73 83 int mazeSize = 12;
el17tc 0:72f372170a73 84 bool beginFlag = false;
el17tc 0:72f372170a73 85 bool restartFlag = false;
el17tc 0:72f372170a73 86 bool menuFlag = false;
el17tc 0:72f372170a73 87 bool timerFlag = true;
el17tc 0:72f372170a73 88
el17tc 0:72f372170a73 89
el17tc 0:72f372170a73 90 #endif // MENUS_H