![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Owen Cavender 201159294
Dependencies: mbed
snake.h@2:ffbfd3f53ee2, 2020-05-30 (annotated)
- Committer:
- el17oc
- Date:
- Sat May 30 06:12:09 2020 +0000
- Revision:
- 2:ffbfd3f53ee2
- Parent:
- 1:897160a1a3ae
Final Submission. I have read and agreed with Statement of Academic Integrity
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17oc | 1:897160a1a3ae | 1 | |
el17oc | 1:897160a1a3ae | 2 | #ifndef SNAKE_H |
el17oc | 1:897160a1a3ae | 3 | #define SNAKE_H |
el17oc | 1:897160a1a3ae | 4 | |
el17oc | 1:897160a1a3ae | 5 | #include "mbed.h" |
el17oc | 1:897160a1a3ae | 6 | #include "N5110.h" |
el17oc | 1:897160a1a3ae | 7 | #include "Gamepad.h" |
el17oc | 1:897160a1a3ae | 8 | |
el17oc | 2:ffbfd3f53ee2 | 9 | /** Snake Class |
el17oc | 2:ffbfd3f53ee2 | 10 | * Owen Cavender, University of Leeds |
el17oc | 2:ffbfd3f53ee2 | 11 | */ |
el17oc | 1:897160a1a3ae | 12 | |
el17oc | 1:897160a1a3ae | 13 | class Snake |
el17oc | 1:897160a1a3ae | 14 | { |
el17oc | 1:897160a1a3ae | 15 | |
el17oc | 1:897160a1a3ae | 16 | |
el17oc | 1:897160a1a3ae | 17 | public: |
el17oc | 1:897160a1a3ae | 18 | Snake(); |
el17oc | 2:ffbfd3f53ee2 | 19 | /** constructor |
el17oc | 2:ffbfd3f53ee2 | 20 | */ |
el17oc | 1:897160a1a3ae | 21 | ~Snake(); |
el17oc | 2:ffbfd3f53ee2 | 22 | /** deconstructor |
el17oc | 2:ffbfd3f53ee2 | 23 | */ |
el17oc | 1:897160a1a3ae | 24 | |
el17oc | 2:ffbfd3f53ee2 | 25 | enum Directions { /**enum of directions*/ |
el17oc | 1:897160a1a3ae | 26 | up, |
el17oc | 1:897160a1a3ae | 27 | down, |
el17oc | 1:897160a1a3ae | 28 | left, |
el17oc | 1:897160a1a3ae | 29 | right, |
el17oc | 2:ffbfd3f53ee2 | 30 | |
el17oc | 1:897160a1a3ae | 31 | }; |
el17oc | 1:897160a1a3ae | 32 | |
el17oc | 1:897160a1a3ae | 33 | void init(); |
el17oc | 2:ffbfd3f53ee2 | 34 | /** initialises 'Snake' class |
el17oc | 2:ffbfd3f53ee2 | 35 | */ |
el17oc | 2:ffbfd3f53ee2 | 36 | void get_direction(Gamepad &pad); |
el17oc | 2:ffbfd3f53ee2 | 37 | /** reads input from gamepad |
el17oc | 2:ffbfd3f53ee2 | 38 | *updates direction |
el17oc | 2:ffbfd3f53ee2 | 39 | */ |
el17oc | 2:ffbfd3f53ee2 | 40 | void render_clear_tail(N5110 &lcd); |
el17oc | 2:ffbfd3f53ee2 | 41 | /** clears pixel on the end of snake |
el17oc | 2:ffbfd3f53ee2 | 42 | *before everything else on the screen is updated and rendered |
el17oc | 2:ffbfd3f53ee2 | 43 | */ |
el17oc | 2:ffbfd3f53ee2 | 44 | void move_snake(); |
el17oc | 2:ffbfd3f53ee2 | 45 | /**alters the values assigned to the snake's body |
el17oc | 2:ffbfd3f53ee2 | 46 | *based on the _direction set in get_direction |
el17oc | 2:ffbfd3f53ee2 | 47 | */ |
el17oc | 2:ffbfd3f53ee2 | 48 | void apple_collected(N5110 &lcd, Gamepad &pad); |
el17oc | 2:ffbfd3f53ee2 | 49 | /** check to see if the apple x,y = snakehead x,y values |
el17oc | 2:ffbfd3f53ee2 | 50 | *increases score, triggers a true which causes generation of apple, updates counter |
el17oc | 2:ffbfd3f53ee2 | 51 | *Plays a tone and toggles LEDs |
el17oc | 2:ffbfd3f53ee2 | 52 | */ |
el17oc | 2:ffbfd3f53ee2 | 53 | void check_gameover(N5110 &lcd); |
el17oc | 2:ffbfd3f53ee2 | 54 | /**checks if game is over based on 3 conditions |
el17oc | 2:ffbfd3f53ee2 | 55 | */ |
el17oc | 2:ffbfd3f53ee2 | 56 | void get_Apple_position(N5110 &lcd); |
el17oc | 2:ffbfd3f53ee2 | 57 | /**sets the apple position |
el17oc | 2:ffbfd3f53ee2 | 58 | *an update of position is triggered by bool _reset_apple |
el17oc | 2:ffbfd3f53ee2 | 59 | */ |
el17oc | 2:ffbfd3f53ee2 | 60 | void render(N5110 &lcd, Gamepad &pad); |
el17oc | 2:ffbfd3f53ee2 | 61 | /**draws the snake, border, and apple during the game |
el17oc | 2:ffbfd3f53ee2 | 62 | * if it is game over, it displays the score and a gameo over message |
el17oc | 2:ffbfd3f53ee2 | 63 | */ |
el17oc | 1:897160a1a3ae | 64 | |
el17oc | 1:897160a1a3ae | 65 | |
el17oc | 1:897160a1a3ae | 66 | |
el17oc | 2:ffbfd3f53ee2 | 67 | Vector2D get_Snakehead(); |
el17oc | 2:ffbfd3f53ee2 | 68 | /**returns _x0, and _y0 values |
el17oc | 2:ffbfd3f53ee2 | 69 | */ |
el17oc | 2:ffbfd3f53ee2 | 70 | |
el17oc | 2:ffbfd3f53ee2 | 71 | int get_countdown(); |
el17oc | 2:ffbfd3f53ee2 | 72 | /**reurns counter value |
el17oc | 2:ffbfd3f53ee2 | 73 | */ |
el17oc | 2:ffbfd3f53ee2 | 74 | int get_score(); |
el17oc | 2:ffbfd3f53ee2 | 75 | /**returns score; |
el17oc | 2:ffbfd3f53ee2 | 76 | */ |
el17oc | 1:897160a1a3ae | 77 | |
el17oc | 1:897160a1a3ae | 78 | private: |
el17oc | 1:897160a1a3ae | 79 | |
el17oc | 2:ffbfd3f53ee2 | 80 | |
el17oc | 2:ffbfd3f53ee2 | 81 | bool get_gameover(); |
el17oc | 2:ffbfd3f53ee2 | 82 | /** returns _gameover |
el17oc | 2:ffbfd3f53ee2 | 83 | *private as it is only used in Snake class |
el17oc | 2:ffbfd3f53ee2 | 84 | */ |
el17oc | 2:ffbfd3f53ee2 | 85 | |
el17oc | 2:ffbfd3f53ee2 | 86 | /**Snake private variables*/ |
el17oc | 1:897160a1a3ae | 87 | Directions _direction; |
el17oc | 2:ffbfd3f53ee2 | 88 | int _countdown; |
el17oc | 2:ffbfd3f53ee2 | 89 | bool _gameover; |
el17oc | 1:897160a1a3ae | 90 | int _score; |
el17oc | 2:ffbfd3f53ee2 | 91 | int _reset_apple; |
el17oc | 1:897160a1a3ae | 92 | |
el17oc | 2:ffbfd3f53ee2 | 93 | int _x0; /**snake position variable*/ |
el17oc | 2:ffbfd3f53ee2 | 94 | int _y0; |
el17oc | 2:ffbfd3f53ee2 | 95 | int _x1; |
el17oc | 2:ffbfd3f53ee2 | 96 | int _y1; |
el17oc | 2:ffbfd3f53ee2 | 97 | int _x2; |
el17oc | 2:ffbfd3f53ee2 | 98 | int _y2; |
el17oc | 2:ffbfd3f53ee2 | 99 | int _x3; |
el17oc | 2:ffbfd3f53ee2 | 100 | int _y3; |
el17oc | 2:ffbfd3f53ee2 | 101 | int _x4; |
el17oc | 2:ffbfd3f53ee2 | 102 | int _y4; |
el17oc | 2:ffbfd3f53ee2 | 103 | int _x5; |
el17oc | 2:ffbfd3f53ee2 | 104 | int _y5; |
el17oc | 2:ffbfd3f53ee2 | 105 | int _x6; |
el17oc | 2:ffbfd3f53ee2 | 106 | int _y6; |
el17oc | 2:ffbfd3f53ee2 | 107 | int _x7; |
el17oc | 2:ffbfd3f53ee2 | 108 | int _y7; |
el17oc | 2:ffbfd3f53ee2 | 109 | |
el17oc | 2:ffbfd3f53ee2 | 110 | |
el17oc | 2:ffbfd3f53ee2 | 111 | int _apx; /**apple position variable*/ |
el17oc | 2:ffbfd3f53ee2 | 112 | int _apy; |
el17oc | 1:897160a1a3ae | 113 | |
el17oc | 1:897160a1a3ae | 114 | }; |
el17oc | 1:897160a1a3ae | 115 | |
el17oc | 1:897160a1a3ae | 116 | |
el17oc | 1:897160a1a3ae | 117 | #endif |