ELEC2645 (2018/19) / Mbed 2 deprecated el18jz_

Dependencies:   mbed

Committer:
jiaxinZHOU
Date:
Wed May 08 22:10:38 2019 +0000
Revision:
1:538386e72e40
Parent:
0:07c4fef6c0af
Child:
2:c7976a633ba0
2nd e

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