ELEC2645 (2018/19) / Mbed 2 deprecated el18jz_

Dependencies:   mbed

Committer:
jiaxinZHOU
Date:
Wed May 08 22:18:51 2019 +0000
Revision:
3:ccbda43c2124
Parent:
2:c7976a633ba0
Child:
4:0f2006e9c8f8
3rd

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