ELEC2645 (2018/19) / Mbed 2 deprecated el18jz_

Dependencies:   mbed

Committer:
jiaxinZHOU
Date:
Thu May 09 02:37:14 2019 +0000
Revision:
4:0f2006e9c8f8
Parent:
3:ccbda43c2124
final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jiaxinZHOU 0:07c4fef6c0af 1 #ifndef MOVE_H
jiaxinZHOU 0:07c4fef6c0af 2 #define MOVE_H
jiaxinZHOU 0:07c4fef6c0af 3
jiaxinZHOU 0:07c4fef6c0af 4 #include "mbed.h"
jiaxinZHOU 0:07c4fef6c0af 5 #include "N5110.h"
jiaxinZHOU 0:07c4fef6c0af 6 #include "Gamepad.h"
jiaxinZHOU 4:0f2006e9c8f8 7 #include "Menu.h"
jiaxinZHOU 0:07c4fef6c0af 8
jiaxinZHOU 3:ccbda43c2124 9
jiaxinZHOU 1:538386e72e40 10
jiaxinZHOU 2:c7976a633ba0 11 /** Snakebody struct */
jiaxinZHOU 0:07c4fef6c0af 12 struct SnakeBody{
jiaxinZHOU 2:c7976a633ba0 13 char _xx[4000];/**< char for x coordinate for each bit of snake body*/
jiaxinZHOU 2:c7976a633ba0 14 char _yy[4000];/**< char for x coordinate for each bit of snake body*/
jiaxinZHOU 2:c7976a633ba0 15 char _dir;/**< char for direction of snake hesd*/
jiaxinZHOU 0:07c4fef6c0af 16
jiaxinZHOU 0:07c4fef6c0af 17 };
jiaxinZHOU 2:c7976a633ba0 18
jiaxinZHOU 2:c7976a633ba0 19 /** Food struct */
jiaxinZHOU 0:07c4fef6c0af 20 struct Food{
jiaxinZHOU 2:c7976a633ba0 21 char a;/**< char for x coordinate for food position*/
jiaxinZHOU 2:c7976a633ba0 22 char b;/**< char for y coordinate for food position*/
jiaxinZHOU 0:07c4fef6c0af 23
jiaxinZHOU 0:07c4fef6c0af 24 };
jiaxinZHOU 3:ccbda43c2124 25 /** Move Class
jiaxinZHOU 3:ccbda43c2124 26 @brief Class for main engine for the snake game
jiaxinZHOU 3:ccbda43c2124 27 @author Zhou Jiaxin
jiaxinZHOU 3:ccbda43c2124 28 @date 8th May 2019
jiaxinZHOU 3:ccbda43c2124 29 */
jiaxinZHOU 0:07c4fef6c0af 30
jiaxinZHOU 0:07c4fef6c0af 31 class Move
jiaxinZHOU 0:07c4fef6c0af 32 {
jiaxinZHOU 0:07c4fef6c0af 33 public:
jiaxinZHOU 1:538386e72e40 34 /** Constructor */
jiaxinZHOU 0:07c4fef6c0af 35 Move();
jiaxinZHOU 1:538386e72e40 36 /** Destructor */
jiaxinZHOU 0:07c4fef6c0af 37 ~Move();
jiaxinZHOU 1:538386e72e40 38
jiaxinZHOU 1:538386e72e40 39 /**
jiaxinZHOU 1:538386e72e40 40 * @brief initial all the parameter for the snake and food.
jiaxinZHOU 1:538386e72e40 41 */
jiaxinZHOU 0:07c4fef6c0af 42 void initial();
jiaxinZHOU 1:538386e72e40 43 /**
jiaxinZHOU 1:538386e72e40 44 * @brief Print snake, walls and food on LCD.
jiaxinZHOU 1:538386e72e40 45 * @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.
jiaxinZHOU 1:538386e72e40 46 */
jiaxinZHOU 0:07c4fef6c0af 47 void onlcd(N5110 &lcd);
jiaxinZHOU 1:538386e72e40 48 /**
jiaxinZHOU 1:538386e72e40 49 * @brief Update new direction and snake head.
jiaxinZHOU 1:538386e72e40 50 * @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.
jiaxinZHOU 1:538386e72e40 51 */
jiaxinZHOU 0:07c4fef6c0af 52 void update(Gamepad &pad);
jiaxinZHOU 1:538386e72e40 53 /**
jiaxinZHOU 1:538386e72e40 54 * @brief Update whole snakebody.
jiaxinZHOU 1:538386e72e40 55 */
jiaxinZHOU 0:07c4fef6c0af 56 void updatebody();
jiaxinZHOU 1:538386e72e40 57 /**
jiaxinZHOU 1:538386e72e40 58 * @brief Use random number to generate a new food on screen while old food has benn eaten.
jiaxinZHOU 1:538386e72e40 59 */
jiaxinZHOU 0:07c4fef6c0af 60 void getfood();
jiaxinZHOU 1:538386e72e40 61 /**
jiaxinZHOU 1:538386e72e40 62 * @brief check if snake head collide the wall or its body.
jiaxinZHOU 1:538386e72e40 63 * @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.
jiaxinZHOU 1:538386e72e40 64 * @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.
jiaxinZHOU 1:538386e72e40 65 */
jiaxinZHOU 0:07c4fef6c0af 66 void die(N5110 &lcd ,Gamepad &pad);
jiaxinZHOU 1:538386e72e40 67 /**
jiaxinZHOU 1:538386e72e40 68 * @brief check if snake head hit the food.
jiaxinZHOU 1:538386e72e40 69 */
jiaxinZHOU 0:07c4fef6c0af 70 void eatfood();
jiaxinZHOU 0:07c4fef6c0af 71
jiaxinZHOU 0:07c4fef6c0af 72 private:
jiaxinZHOU 0:07c4fef6c0af 73
jiaxinZHOU 0:07c4fef6c0af 74 int _x;
jiaxinZHOU 0:07c4fef6c0af 75 int _y;
jiaxinZHOU 0:07c4fef6c0af 76 int _length;
jiaxinZHOU 0:07c4fef6c0af 77 Direction _d;
jiaxinZHOU 4:0f2006e9c8f8 78 Menu menu;
jiaxinZHOU 4:0f2006e9c8f8 79 int _fps;
jiaxinZHOU 0:07c4fef6c0af 80
jiaxinZHOU 0:07c4fef6c0af 81 };
jiaxinZHOU 0:07c4fef6c0af 82 #endif