ELEC2645 (2018/19) / Mbed 2 deprecated el18jz_

Dependencies:   mbed

Committer:
jiaxinZHOU
Date:
Wed May 08 22:17:34 2019 +0000
Revision:
2:c7976a633ba0
Parent:
1:538386e72e40
Child:
3:ccbda43c2124
q

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