![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Owen Cavender 201159294
Dependencies: mbed
Diff: snake.h
- Revision:
- 2:ffbfd3f53ee2
- Parent:
- 1:897160a1a3ae
diff -r 897160a1a3ae -r ffbfd3f53ee2 snake.h --- a/snake.h Tue May 26 12:17:59 2020 +0000 +++ b/snake.h Sat May 30 06:12:09 2020 +0000 @@ -5,8 +5,10 @@ #include "mbed.h" #include "N5110.h" #include "Gamepad.h" -#include "GameEngine.h" +/** Snake Class +* Owen Cavender, University of Leeds +*/ class Snake { @@ -14,37 +16,100 @@ public: Snake(); + /** constructor + */ ~Snake(); + /** deconstructor + */ - enum Directions { + enum Directions { /**enum of directions*/ up, down, left, right, - null + }; void init(); - int set_direction(Gamepad &pad); - //Directions get_direction(); - void move_and_draw_snake(N5110 &lcd); - void gameover_true(N5110 &lcd); - void check_if_scored(N5110 &lcd, Gamepad &pad); - void check_wall_collisions(); - // void render(N5110 &lcd); - void clear_applepos(N5110 &lcd); + /** initialises 'Snake' class + */ + void get_direction(Gamepad &pad); + /** reads input from gamepad + *updates direction + */ + void render_clear_tail(N5110 &lcd); + /** clears pixel on the end of snake + *before everything else on the screen is updated and rendered + */ + void move_snake(); + /**alters the values assigned to the snake's body + *based on the _direction set in get_direction + */ + void apple_collected(N5110 &lcd, Gamepad &pad); + /** check to see if the apple x,y = snakehead x,y values + *increases score, triggers a true which causes generation of apple, updates counter + *Plays a tone and toggles LEDs + */ + void check_gameover(N5110 &lcd); + /**checks if game is over based on 3 conditions + */ + void get_Apple_position(N5110 &lcd); + /**sets the apple position + *an update of position is triggered by bool _reset_apple + */ + void render(N5110 &lcd, Gamepad &pad); + /**draws the snake, border, and apple during the game + * if it is game over, it displays the score and a gameo over message + */ + Vector2D get_Snakehead(); + /**returns _x0, and _y0 values + */ + + int get_countdown(); + /**reurns counter value + */ + int get_score(); + /**returns score; + */ private: - bool _gameover; + + bool get_gameover(); + /** returns _gameover + *private as it is only used in Snake class + */ + + /**Snake private variables*/ Directions _direction; - int _length; + int _countdown; + bool _gameover; int _score; - GameEngine _engine; + int _reset_apple; + int _x0; /**snake position variable*/ + int _y0; + int _x1; + int _y1; + int _x2; + int _y2; + int _x3; + int _y3; + int _x4; + int _y4; + int _x5; + int _y5; + int _x6; + int _y6; + int _x7; + int _y7; + + + int _apx; /**apple position variable*/ + int _apy; };