Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Move.h
00001 #ifndef MOVE_H 00002 #define MOVE_H 00003 00004 #include "mbed.h" 00005 #include "N5110.h" 00006 #include "Gamepad.h" 00007 #include "Menu.h" 00008 00009 00010 00011 /** Snakebody struct */ 00012 struct SnakeBody{ 00013 char _xx[4000];/**< char for x coordinate for each bit of snake body*/ 00014 char _yy[4000];/**< char for x coordinate for each bit of snake body*/ 00015 char _dir;/**< char for direction of snake hesd*/ 00016 00017 }; 00018 00019 /** Food struct */ 00020 struct Food{ 00021 char a;/**< char for x coordinate for food position*/ 00022 char b;/**< char for y coordinate for food position*/ 00023 00024 }; 00025 /** Move Class 00026 @brief Class for main engine for the snake game 00027 @author Zhou Jiaxin 00028 @date 8th May 2019 00029 */ 00030 00031 class Move 00032 { 00033 public: 00034 /** Constructor */ 00035 Move(); 00036 /** Destructor */ 00037 ~Move(); 00038 00039 /** 00040 * @brief initial all the parameter for the snake and food. 00041 */ 00042 void initial(); 00043 /** 00044 * @brief Print snake, walls and food on LCD. 00045 * @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. 00046 */ 00047 void onlcd(N5110 &lcd); 00048 /** 00049 * @brief Update new direction and snake head. 00050 * @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. 00051 */ 00052 void update(Gamepad &pad); 00053 /** 00054 * @brief Update whole snakebody. 00055 */ 00056 void updatebody(); 00057 /** 00058 * @brief Use random number to generate a new food on screen while old food has benn eaten. 00059 */ 00060 void getfood(); 00061 /** 00062 * @brief check if snake head collide the wall or its body. 00063 * @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. 00064 * @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. 00065 */ 00066 void die(N5110 &lcd ,Gamepad &pad); 00067 /** 00068 * @brief check if snake head hit the food. 00069 */ 00070 void eatfood(); 00071 00072 private: 00073 00074 int _x; 00075 int _y; 00076 int _length; 00077 Direction _d; 00078 Menu menu; 00079 int _fps; 00080 00081 }; 00082 #endif
Generated on Tue Jul 12 2022 22:27:32 by
1.7.2