Menu class used as basis for program; running the game and allowing the user to change the style and difficulty of the game via an interface.
Revision 6:2a05dd8b9750, committed 2017-05-04
- Comitter:
- el15mh
- Date:
- Thu May 04 14:01:32 2017 +0000
- Parent:
- 5:56f13954666e
- Commit message:
- Doxygen commenting added
Changed in this revision
Menu.cpp | Show annotated file Show diff for this revision Revisions of this file |
Menu.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 56f13954666e -r 2a05dd8b9750 Menu.cpp --- a/Menu.cpp Wed May 03 21:13:31 2017 +0000 +++ b/Menu.cpp Thu May 04 14:01:32 2017 +0000 @@ -1,12 +1,3 @@ -/* - - @file Menu.cpp - - (c) Max Houghton 02.04.17 - Roller Maze Project, ELEC2645, Univeristy of Leeds - - */ - #include "Menu.h" // constructor function used when object is initialised @@ -21,10 +12,13 @@ } +/** + * @details - Initiases the game with default parameters before value specification +*/ void Menu::init() { // set all default game parameters - _difficulty = 4; + _difficulty = 1; _FPS = 50; _control = true; @@ -32,7 +26,10 @@ _tone = true; } -/// MAIN MENU METHOD /// +/** + * @details - Main menu function. + + */ void Menu::main(N5110 &lcd, Gamepad &pad, FXOS8700CQ &device, Animations &animate) { int selected = 0; @@ -178,7 +175,9 @@ } } -/// INTRO LOOP /// +/** + * @details - Game introduction function. + */ void Menu::intro(N5110 &lcd, Gamepad &pad, Animations &animate) { // printf("intro started \n"); @@ -188,7 +187,9 @@ } } -/// GAME LOOP /// +/** + * @details - Game Loop function. + */ void Menu::playGame(N5110 &lcd, Gamepad &pad, FXOS8700CQ &device, @@ -206,7 +207,7 @@ // pairs of values with corresponding difficulties _FPS = 100 - FPS; - // from function, low FPS value corresponds to fast gameplay + // from game speed fuction (line , low FPS value corresponds to fast gameplay // so perform basic inversion (works when value is between 25 - 75) if (difficulty == 1) { @@ -284,6 +285,9 @@ } } +/** + * @details - Returns a random number between two set values + */ int Menu::randomMazeIndexGenerator(int difficulty) { // generates a random number between a pair of values @@ -314,6 +318,9 @@ return _mazeIndex; } +/** + * @details - Prints all chosen game parameters to serial port - used mostly for debugging. + */ void Menu::printGameParameters(int mazeIndex, int x, int y, @@ -353,7 +360,9 @@ } -/// MENU FUNCTIONS /// +/** + * @details - Game Options Function to allow user to choose game style. + */ void Menu::options(N5110 &lcd, Gamepad &pad, Animations &animate, bool tone) { int exit = 0; @@ -511,6 +520,9 @@ } } +/** + * @details - LCD Settings Function to allow user to alter appearance of game on LCD. + */ void Menu::lcdSettings(N5110 &lcd, Gamepad &pad, Animations &animate) { int exit = 0; @@ -610,6 +622,9 @@ } +/** + * @details - Sound Settings to allow user to turn sound on or off + */ void Menu::soundSettings(N5110 &lcd, Gamepad &pad, Animations &animate) { int exit = 0; @@ -665,6 +680,9 @@ } +/** + * @details - Control Options Function which allows user select control technique. + */ void Menu::controlOptions(N5110 &lcd, Gamepad &pad, Animations &animate) { int selected = 0; @@ -763,7 +781,9 @@ } } - +/** + * @details - Difficulty Options Function to allow player to select difficulty level. + */ void Menu::difficultyOptions(N5110 &lcd, Gamepad &pad) { int selected = 0; @@ -944,6 +964,9 @@ } } +/** + * @details - Ball colour function to select the style of ball used in the game. + */ void Menu::ballColourOptions(N5110 &lcd, Gamepad &pad, Animations &animate) { int selected = 0; @@ -1048,6 +1071,9 @@ } +/** + * @details - LCD Inverse Colour function which allows user to switch colours on the LCD. + */ void Menu::lcdInverseColour(N5110 &lcd, Gamepad &pad) { int exit = 0; @@ -1093,6 +1119,9 @@ } +/** + * @details - LCD Inverse Colour function which changes the PWM value of the LCD backlight LED. + */ void Menu::lcdBackgroundColour(N5110 &lcd, Gamepad &pad, Animations &animate) { // method to change the brightness of the LED backlight @@ -1131,6 +1160,9 @@ } } +/** + * @details - Game Speed function which changes the FPS used in the game loop. + */ void Menu::speedSettings(N5110 &lcd, Gamepad &pad) { int exit = 0; @@ -1181,6 +1213,9 @@ } } +/** + * @details - Animate Joystick function creats a short animation of moving joystick. + */ void Menu::animateJoystick(N5110 &lcd, Animations &animate) { int timer = 0; @@ -1220,7 +1255,9 @@ } } - +/** + * @details - Animate Gamepad function creats a short animation of moving gamepad. + */ void Menu::animateGamepad(N5110 &lcd, Animations &animate) { int timer = 0; @@ -1261,6 +1298,9 @@ } } +/** + * @details - Animate Stickman function creates a short animation of jumping man to signify goal reached. + */ void Menu::animateStickman(N5110 &lcd, Gamepad &pad, Animations &animate) { int timer = 0;
diff -r 56f13954666e -r 2a05dd8b9750 Menu.h --- a/Menu.h Wed May 03 21:13:31 2017 +0000 +++ b/Menu.h Thu May 04 14:01:32 2017 +0000 @@ -1,10 +1,7 @@ -/* - - @file Menu.h - - (c) Max Houghton 02.14.17 - Roller Maze Project, ELEC2645, Univeristy of Leeds - +/** Menu Class + @brief Class runs the menu which the program uses as a basis. + @author Max Houghton + @date April 4 2017 */ #ifndef MENU_H @@ -20,27 +17,86 @@ #include "Maze.h" #include "Ball.h" -#define G 196.00 -#define C - class Menu { public: + /** + * @details - constructor + */ Menu(); + + /** + * @details - destructor + */ ~Menu(); + /** Initialise Menu + * + * @details - Creates objects and default parameters for the game + * + */ void init(); + + /** Main Menu Function + * + * @details - The main function which runs the game and allows player to select all different game parameters. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. + * @param - device - FXOS8700CQ Libary, used to read data from accelerometer + * @param - animate - Animations Library to provide short animations. + * + */ void main(N5110 &lcd, Gamepad &pad, FXOS8700CQ &device, Animations &animate); + /** Intro Function + * + * @details - The main function which runs the game and allows player to select all different game parameters. + * @details - Called from main file when the game is loading. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. + * @param - animate - Animations Library to provide short animations. + * + */ void intro(N5110 &lcd, Gamepad &pad, Animations &animate); private: + /** + * + * @details - Game Loop function. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. + * @param - device - FXOS8700CQ Libary, used to read data from accelerometer + * @param - animate - Animations Library to provide short animations. + * @param - difficulty - Integer value to specificy desired difficulty; maze Index is randomly chosen according to difficulty value. + * @param - tone - Boolean value to select whether sound is used or not. + * @param - FPS - Specifies the frame rate at which the game is to be played at. + * + */ + void playGame(N5110 &lcd, + Gamepad &pad, + FXOS8700CQ &device, + Animations &animate, + int mazeIndex, + bool tone, + float FPS); + + /** + * + * @details - Prints all chosen game parameters to serial port - used mostly for debugging. + * @param - mazeIndex - specifies which of the 10 mazes is to be drawn. + * @param - x - x coordiante for centre of ball when drawn initially. + * @param - y - y coordiante for centre of ball when drawn initially. + * @param - control - Boolean value to specify desired control method. + * @param - colour - Boolean value to select type of ball; filled or transparent. + * @param - FPS - Specifies the frame rate at which the game is to be played at. + * + */ void printGameParameters(int mazeIndex, int x, int y, @@ -49,42 +105,165 @@ bool colour, float FPS); - void playGame(N5110 &lcd, - Gamepad &pad, - FXOS8700CQ &device, - Animations &animate, - int mazeIndex, - bool tone, - float FPS); + + /** + * + * @details - Game Options Function to allow user to choose game style. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. + * @param - animate - Animations Library to provide short animations. + * @param - tone - Boolean value to select whether sound is used or not. + */ + void options(N5110 &lcd, Gamepad &pad, Animations &animate, bool tone); + + + /** + * + * @details - LCD Settings Function to allow user to alter appearance of game on LCD. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. + * @param - animate - Animations Library to provide short animations. + * + */ + void lcdSettings(N5110 &lcd, Gamepad &pad, Animations &animate); + + /** + * + * @details - Sound Settings to allow user to turn sound on or off. This changes the boolean value of the '_tone' variable. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. + * @param - animate - Animations Library to animate slide bar to display brightness level settings. + * + */ + void soundSettings(N5110 &lcd, Gamepad &pad, Animations &animate); - void options(N5110 &lcd, Gamepad &pad, Animations &animate, bool tone); - void lcdSettings(N5110 &lcd, Gamepad &pad, Animations &animate); - void soundSettings(N5110 &lcd, Gamepad &pad, Animations &animate); + /** + * + * @details - Control Options Function which allows user select control technique. This chanes the boolean value of the '_control' variable. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. + * @param - animate -Animations Library to provide animations for either joystick or gamepad tilt selection. + * + */ void controlOptions(N5110 &lcd, Gamepad &pad, Animations &animate); + + /** + * + * @details - Difficulty Options Function to allow player to select difficulty level. This changes the value of integer variable '_difficulty' to 1, 2, 3 or 4. The maze index for the maze is then selected randomly according to this difficulty value. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. + * + */ void difficultyOptions(N5110 &lcd, Gamepad &pad); + + /** + * + * @details - Ball colour function to select the style of ball used in the game. This function changes the value of boolean variable '_colour'; true corresponds to a transparent fill and false to solid fill. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. + * @param - animate - Animations Library to provide animations for either solid or transparent fill selection. + * + */ void ballColourOptions(N5110 &lcd, Gamepad &pad, Animations &animate); + + /** + *s + * @details - LCD Inverse Colour function which allows user to switch colours on the LCD. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. + * + */ void lcdInverseColour(N5110 &lcd, Gamepad &pad); + + /** + * @details - LCD Background Colour function which changes the PWM value of the LCD backlight LED. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. + * @param - animate - Animations Library to provide animation for switch. + */ void lcdBackgroundColour(N5110 &lcd, Gamepad &pad, Animations &animate); + /** + * @details - Animate Joystick function creats a short animation of moving joystick. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - animate - Animations Library to provide animation for moving joystick bitmaps. + */ void animateJoystick(N5110 &lcd, Animations &animate); + + /** + * @details - Animate Gamepad function creats a short animation of moving gamepad. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - animate - Animations Library to provide animation for moving gamepad bitmaps. + */ void animateGamepad(N5110 &lcd, Animations &animate); + + /** + * @details - Animate Stickman function creates a short animation of jumping man to signify goal reached. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to flash LEDS on and off. + * @param - animate - Animations Library to provide animation for moving stickman bitmap. + */ void animateStickman(N5110 &lcd, Gamepad &pad, Animations &animate); - void soundEffects(N5110 &lcd, Gamepad &pad, Animations &animate); + /** + * @details - Game Speed function which changes the FPS used in the game loop. + * @param - lcd - N5110 Library, used for drawing strings and printing bitmaps + * @param - pad - Gamepad Library, used to read inputs from peripheral devides on the handheld gamepad device. + */ void speedSettings(N5110 &lcd, Gamepad &pad); + /** + * @details - Returns a random number between two set values + * @param - difficulty - Specified value dictating the level of maze to be played + */ int randomMazeIndexGenerator(int difficulty); + /** + * @details - Creates _engine object to be used when running the game loop. + * @param - _engine - instance of MazeEngine class. + */ MazeEngine _engine; + /** + * @details - Integer to select the specific maze to be drawn by engine. + * @param - _mazeIndex - variable to be passed down to engine. + */ int _mazeIndex; + + /** + * @details - Integer to select the desired difficulty by user. + * @param - _difficulty - variable to be passed down to engine. Value used in randomMazeIndexGenerator() function + */ int _difficulty; + /** + * @details - Integer to select the frame rate at which the game is updated at. + * @param - _FPS - value is used as delay between updates when running game loop + */ float _FPS; + /** + * @details - Boolean value to select the desired control method by user. + * @param - _control - value of true corresponds to joystick input, false corresponds to accelerometer values used as input. + */ bool _control; + + /** + * @details - Boolean value to select the desired ball fill type. + * @param - _control - value of true corresponds to transparent fill, false corresponds to solid fill of ball when playing the game. + */ bool _colour; + + /** + * @details - Boolean value to signify when the goal has been reached. + * @param - _goal - when this variable becomes true, the particular maze has been completed. + */ bool _goal; + + /** + * @details - Boolean value to dictate if the buzzer on the gamepad is to be used in the menu when moving between options or selecting desired parameters. + * @param - _tone - A true value allows for sound to be used in the menu. + */ bool _tone; };