Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Wed May 08 23:08:49 2019 +0000
Revision:
93:7f9c31ed5cab
Parent:
83:329da564799a
Documented WinLoose and LengthManager

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AhmedPlaymaker 79:35cb65c52d25 1 #ifndef LENGTHMANAGER_H
AhmedPlaymaker 79:35cb65c52d25 2 #define LENGTHMANAGER_H
AhmedPlaymaker 79:35cb65c52d25 3
AhmedPlaymaker 79:35cb65c52d25 4 #include "mbed.h"
AhmedPlaymaker 79:35cb65c52d25 5 #include "N5110.h"
AhmedPlaymaker 79:35cb65c52d25 6 #include "Gamepad.h"
AhmedPlaymaker 79:35cb65c52d25 7
AhmedPlaymaker 93:7f9c31ed5cab 8 /** LengthManager Class
AhmedPlaymaker 93:7f9c31ed5cab 9 @brief This class calculates the length of the snake at every point during the game and can be used to set length values in other classes using _getLength().
AhmedPlaymaker 93:7f9c31ed5cab 10 @author Ahmed N.Adamjee
AhmedPlaymaker 93:7f9c31ed5cab 11 @date 8th May 2019
AhmedPlaymaker 93:7f9c31ed5cab 12 */
AhmedPlaymaker 79:35cb65c52d25 13 class LengthManager
AhmedPlaymaker 79:35cb65c52d25 14 {
AhmedPlaymaker 79:35cb65c52d25 15 public:
AhmedPlaymaker 93:7f9c31ed5cab 16 /** Constructor */
AhmedPlaymaker 79:35cb65c52d25 17 LengthManager();
AhmedPlaymaker 93:7f9c31ed5cab 18 /** Destructor */
AhmedPlaymaker 79:35cb65c52d25 19 ~LengthManager();
AhmedPlaymaker 79:35cb65c52d25 20
AhmedPlaymaker 93:7f9c31ed5cab 21 /**
AhmedPlaymaker 93:7f9c31ed5cab 22 * @brief This function sets the initial length parameters and gets pointers of lcd and pad from int main() to be used privately in the entire class.
AhmedPlaymaker 93:7f9c31ed5cab 23 * @param N5110 *lcd @details pointer to the N5110 object in main, address of this pointer is saved to make availability to the entire class, without passing address to each function.
AhmedPlaymaker 93:7f9c31ed5cab 24 * @param Gamepad *pad @details pointer to the gamepad object in main, address of this pointer is saved to make availability to the entire class, without passing address to each function.
AhmedPlaymaker 93:7f9c31ed5cab 25 @code
AhmedPlaymaker 93:7f9c31ed5cab 26 _lcd = lcd;
AhmedPlaymaker 93:7f9c31ed5cab 27 _length = 4;
AhmedPlaymaker 93:7f9c31ed5cab 28 @endcode
AhmedPlaymaker 79:35cb65c52d25 29 */
AhmedPlaymaker 83:329da564799a 30 void init(N5110 *lcd);
AhmedPlaymaker 79:35cb65c52d25 31
AhmedPlaymaker 93:7f9c31ed5cab 32 /**
AhmedPlaymaker 93:7f9c31ed5cab 33 * @brief This function decrements the length value by 1;
AhmedPlaymaker 93:7f9c31ed5cab 34 @code
AhmedPlaymaker 93:7f9c31ed5cab 35 _length -= 1;
AhmedPlaymaker 93:7f9c31ed5cab 36 @endcode
AhmedPlaymaker 79:35cb65c52d25 37 */
AhmedPlaymaker 79:35cb65c52d25 38 void MinusLength();
AhmedPlaymaker 79:35cb65c52d25 39
AhmedPlaymaker 93:7f9c31ed5cab 40 /**
AhmedPlaymaker 93:7f9c31ed5cab 41 * @brief This function increments the length by one.
AhmedPlaymaker 93:7f9c31ed5cab 42 @code
AhmedPlaymaker 93:7f9c31ed5cab 43 _length += 1;
AhmedPlaymaker 93:7f9c31ed5cab 44 @endcode
AhmedPlaymaker 79:35cb65c52d25 45 */
AhmedPlaymaker 79:35cb65c52d25 46 void PlusLength();
AhmedPlaymaker 79:35cb65c52d25 47
AhmedPlaymaker 93:7f9c31ed5cab 48 /**
AhmedPlaymaker 93:7f9c31ed5cab 49 * @brief This function prints the length on top edge of screen.
AhmedPlaymaker 93:7f9c31ed5cab 50 @code
AhmedPlaymaker 93:7f9c31ed5cab 51 char bufferscore[14];
AhmedPlaymaker 93:7f9c31ed5cab 52 sprintf(bufferscore,"%d",_length);
AhmedPlaymaker 93:7f9c31ed5cab 53 _lcd->printString(bufferscore,1,0);
AhmedPlaymaker 93:7f9c31ed5cab 54 @endcode
AhmedPlaymaker 79:35cb65c52d25 55 */
AhmedPlaymaker 83:329da564799a 56 void print_length_on_screen();
AhmedPlaymaker 79:35cb65c52d25 57
AhmedPlaymaker 93:7f9c31ed5cab 58 /**
AhmedPlaymaker 93:7f9c31ed5cab 59 * @brief This sends the current length value when called.
AhmedPlaymaker 93:7f9c31ed5cab 60 * @returns _length @details This is the length of the snake, which is passed back after any manipulation such as MinusLength() or PlusLength().
AhmedPlaymaker 93:7f9c31ed5cab 61 @code
AhmedPlaymaker 93:7f9c31ed5cab 62 return _length;
AhmedPlaymaker 93:7f9c31ed5cab 63 @endcode
AhmedPlaymaker 79:35cb65c52d25 64 */
AhmedPlaymaker 79:35cb65c52d25 65 int _getLength();
AhmedPlaymaker 79:35cb65c52d25 66
AhmedPlaymaker 93:7f9c31ed5cab 67 /**
AhmedPlaymaker 93:7f9c31ed5cab 68 * @brief This function obtains the length value to be altered for a specific operation.
AhmedPlaymaker 93:7f9c31ed5cab 69 * @param length @details This is the length of the snake, which is recieved from the calling function to either initialise this or update this.
AhmedPlaymaker 93:7f9c31ed5cab 70 @code
AhmedPlaymaker 93:7f9c31ed5cab 71 _length = length;
AhmedPlaymaker 93:7f9c31ed5cab 72 @endcode
AhmedPlaymaker 79:35cb65c52d25 73 */
AhmedPlaymaker 79:35cb65c52d25 74 void _setLength(int length);
AhmedPlaymaker 79:35cb65c52d25 75
AhmedPlaymaker 79:35cb65c52d25 76 private:
AhmedPlaymaker 79:35cb65c52d25 77 int _length;
AhmedPlaymaker 83:329da564799a 78 //Pointer to the game pad object pad.
AhmedPlaymaker 83:329da564799a 79 Gamepad *_pad;
AhmedPlaymaker 83:329da564799a 80 //Pointer to the N5110 object lcd.
AhmedPlaymaker 83:329da564799a 81 N5110 *_lcd;
AhmedPlaymaker 79:35cb65c52d25 82
AhmedPlaymaker 79:35cb65c52d25 83 };
AhmedPlaymaker 79:35cb65c52d25 84 #endif