Li Saiwen 201089052
Dependencies: mbed Gamepad N5110
Snake/Snake.h@7:cafa0b96e8d3, 2019-05-05 (annotated)
- Committer:
- 1012754868
- Date:
- Sun May 05 12:10:48 2019 +0000
- Revision:
- 7:cafa0b96e8d3
- Parent:
- 6:1ad8c738b9b7
- Child:
- 9:5f73221012bf
Fix some bug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
1012754868 | 3:7b28047013d2 | 1 | #ifndef SNAKE_H |
1012754868 | 3:7b28047013d2 | 2 | #define SNAKE_H |
1012754868 | 3:7b28047013d2 | 3 | |
1012754868 | 3:7b28047013d2 | 4 | #include "mbed.h" |
1012754868 | 3:7b28047013d2 | 5 | #include "N5110.h" |
1012754868 | 3:7b28047013d2 | 6 | #include "Gamepad.h" |
1012754868 | 3:7b28047013d2 | 7 | #include "Food.h" |
1012754868 | 4:c30fb57e0d42 | 8 | |
1012754868 | 7:cafa0b96e8d3 | 9 | |
1012754868 | 3:7b28047013d2 | 10 | struct snakePart{ |
1012754868 | 3:7b28047013d2 | 11 | char _x[4000]; |
1012754868 | 3:7b28047013d2 | 12 | char _y[4000]; |
1012754868 | 3:7b28047013d2 | 13 | char _dirc[4000]; |
1012754868 | 3:7b28047013d2 | 14 | |
1012754868 | 3:7b28047013d2 | 15 | }; |
1012754868 | 3:7b28047013d2 | 16 | |
1012754868 | 7:cafa0b96e8d3 | 17 | |
1012754868 | 5:c5fa3fea1a20 | 18 | |
1012754868 | 5:c5fa3fea1a20 | 19 | /** My Snake Class |
1012754868 | 5:c5fa3fea1a20 | 20 | * @brief Class for defining snake's properties and states |
1012754868 | 5:c5fa3fea1a20 | 21 | * @author Li Saiwen |
1012754868 | 5:c5fa3fea1a20 | 22 | * @date May, 2019 |
1012754868 | 5:c5fa3fea1a20 | 23 | */ |
1012754868 | 4:c30fb57e0d42 | 24 | class Snake{ |
1012754868 | 3:7b28047013d2 | 25 | |
1012754868 | 3:7b28047013d2 | 26 | public: |
1012754868 | 3:7b28047013d2 | 27 | |
1012754868 | 4:c30fb57e0d42 | 28 | /** Constructor */ |
1012754868 | 3:7b28047013d2 | 29 | Snake(); |
1012754868 | 4:c30fb57e0d42 | 30 | |
1012754868 | 4:c30fb57e0d42 | 31 | /** Destructor */ |
1012754868 | 3:7b28047013d2 | 32 | ~Snake(); |
1012754868 | 4:c30fb57e0d42 | 33 | |
1012754868 | 4:c30fb57e0d42 | 34 | /** initial snake's property |
1012754868 | 4:c30fb57e0d42 | 35 | * @param the value of the initial cooridnate_x(int), coordinate_y(int), length(int), live(int) |
1012754868 | 4:c30fb57e0d42 | 36 | */ |
1012754868 | 4:c30fb57e0d42 | 37 | void init(int x, int y, int length,int _live); |
1012754868 | 4:c30fb57e0d42 | 38 | |
1012754868 | 4:c30fb57e0d42 | 39 | /** draw snake |
1012754868 | 4:c30fb57e0d42 | 40 | * @param the subclass of N5110(lcd) and Gamepad(pad) |
1012754868 | 4:c30fb57e0d42 | 41 | */ |
1012754868 | 3:7b28047013d2 | 42 | void drawsnake(N5110 &lcd, Gamepad &pad); |
1012754868 | 4:c30fb57e0d42 | 43 | |
1012754868 | 4:c30fb57e0d42 | 44 | /** Determine the movement of snake |
1012754868 | 4:c30fb57e0d42 | 45 | * @param the subclass of Gamepad(pad) |
1012754868 | 4:c30fb57e0d42 | 46 | */ |
1012754868 | 3:7b28047013d2 | 47 | void snakemov(Gamepad &pad); |
1012754868 | 4:c30fb57e0d42 | 48 | |
1012754868 | 4:c30fb57e0d42 | 49 | /** Determine if the snake is dead |
1012754868 | 4:c30fb57e0d42 | 50 | * @param the subclass of N5110(lcd) and Gamepad(pad) |
1012754868 | 6:1ad8c738b9b7 | 51 | * @return return 0 |
1012754868 | 4:c30fb57e0d42 | 52 | */ |
1012754868 | 3:7b28047013d2 | 53 | int dead(N5110 &lcd, Gamepad &pad); |
1012754868 | 4:c30fb57e0d42 | 54 | |
1012754868 | 4:c30fb57e0d42 | 55 | /** Determine if the snake eats food |
1012754868 | 4:c30fb57e0d42 | 56 | * @param the subclass of Gamepad(pad) |
1012754868 | 4:c30fb57e0d42 | 57 | */ |
1012754868 | 3:7b28047013d2 | 58 | void eat(Gamepad &pad); |
1012754868 | 4:c30fb57e0d42 | 59 | |
1012754868 | 4:c30fb57e0d42 | 60 | /** Determine if the snake collide the wall |
1012754868 | 4:c30fb57e0d42 | 61 | * @param the subclass of N5110(lcd) and Gamepad(pad) |
1012754868 | 4:c30fb57e0d42 | 62 | */ |
1012754868 | 3:7b28047013d2 | 63 | void check_WallCollision(N5110 &lcd, Gamepad &pad); |
1012754868 | 4:c30fb57e0d42 | 64 | |
1012754868 | 4:c30fb57e0d42 | 65 | /** Determine if the snake collide the tail |
1012754868 | 4:c30fb57e0d42 | 66 | * @param the subclass of N5110(lcd) and Gamepad(pad) |
1012754868 | 4:c30fb57e0d42 | 67 | */ |
1012754868 | 3:7b28047013d2 | 68 | void check_TailCollision(N5110 &lcd, Gamepad &pad); |
1012754868 | 4:c30fb57e0d42 | 69 | |
1012754868 | 4:c30fb57e0d42 | 70 | /** Draw the current health points and score |
1012754868 | 4:c30fb57e0d42 | 71 | * @param the subclass of N5110(lcd) |
1012754868 | 4:c30fb57e0d42 | 72 | */ |
1012754868 | 3:7b28047013d2 | 73 | void drawscore(N5110 &lcd); |
1012754868 | 4:c30fb57e0d42 | 74 | |
1012754868 | 4:c30fb57e0d42 | 75 | /** Make a noise when eating food |
1012754868 | 4:c30fb57e0d42 | 76 | * @param the subclass of Gamepad(pad) |
1012754868 | 4:c30fb57e0d42 | 77 | */ |
1012754868 | 3:7b28047013d2 | 78 | void Tone_1(Gamepad &pad); |
1012754868 | 4:c30fb57e0d42 | 79 | |
1012754868 | 4:c30fb57e0d42 | 80 | /** Make a noise when collide wall |
1012754868 | 4:c30fb57e0d42 | 81 | * @param the subclass of Gamepad(pad) |
1012754868 | 4:c30fb57e0d42 | 82 | */ |
1012754868 | 3:7b28047013d2 | 83 | void game_music(Gamepad &pad); |
1012754868 | 3:7b28047013d2 | 84 | int _length; |
1012754868 | 3:7b28047013d2 | 85 | int live; |
1012754868 | 3:7b28047013d2 | 86 | float waitTime; |
1012754868 | 3:7b28047013d2 | 87 | float waitExpect; |
1012754868 | 3:7b28047013d2 | 88 | int _speed; |
1012754868 | 3:7b28047013d2 | 89 | int Highest_score; |
1012754868 | 3:7b28047013d2 | 90 | |
1012754868 | 3:7b28047013d2 | 91 | |
1012754868 | 7:cafa0b96e8d3 | 92 | |
1012754868 | 3:7b28047013d2 | 93 | private: |
1012754868 | 3:7b28047013d2 | 94 | |
1012754868 | 3:7b28047013d2 | 95 | int _direction; |
1012754868 | 3:7b28047013d2 | 96 | int initx; |
1012754868 | 3:7b28047013d2 | 97 | int inity; |
1012754868 | 3:7b28047013d2 | 98 | int initl; |
1012754868 | 3:7b28047013d2 | 99 | int x; |
1012754868 | 3:7b28047013d2 | 100 | Direction d; |
1012754868 | 3:7b28047013d2 | 101 | Food _food; |
1012754868 | 3:7b28047013d2 | 102 | |
1012754868 | 3:7b28047013d2 | 103 | |
1012754868 | 3:7b28047013d2 | 104 | }; |
1012754868 | 3:7b28047013d2 | 105 | |
1012754868 | 3:7b28047013d2 | 106 | #endif |