Final Commit

Dependencies:   mbed

Committer:
JRM1986
Date:
Tue May 08 12:32:46 2018 +0000
Revision:
27:bd0f69a75d8b
Parent:
26:23301f48c1ed
Final Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JRM1986 2:ea90cec2489a 1 #ifndef SNAKE_H
JRM1986 2:ea90cec2489a 2 #define SNAKE_H
JRM1986 2:ea90cec2489a 3
JRM1986 2:ea90cec2489a 4 #include "mbed.h"
JRM1986 3:50f01159c61d 5 #include "Gamepad.h"
JRM1986 2:ea90cec2489a 6 #include "N5110.h"
JRM1986 9:561e5681b7a6 7
JRM1986 2:ea90cec2489a 8 /** Snake Class
JRM1986 22:7f81fca01f02 9 * @brief Describes the methods and functions for the snake head
JRM1986 1:c3fdbc4b1293 10 * @author Joshua R. Marshall
JRM1986 1:c3fdbc4b1293 11 * @date Feb, 2018
JRM1986 2:ea90cec2489a 12 */
JRM1986 9:561e5681b7a6 13
JRM1986 2:ea90cec2489a 14 class Snake
JRM1986 2:ea90cec2489a 15 {
JRM1986 2:ea90cec2489a 16
JRM1986 2:ea90cec2489a 17 public:
JRM1986 9:561e5681b7a6 18
JRM1986 2:ea90cec2489a 19 Snake(); // constructor
JRM1986 2:ea90cec2489a 20 ~Snake(); // destructor
JRM1986 13:72bc2579e85e 21
JRM1986 22:7f81fca01f02 22 /** Initialises the snakes direction and position when game starts
JRM1986 23:3081be418c89 23 * @param Input direction from pad
JRM1986 23:3081be418c89 24 * @param Current direction of snake
JRM1986 23:3081be418c89 25 * @param pos_x x position
JRM1986 23:3081be418c89 26 * @param pos_y y position
JRM1986 22:7f81fca01f02 27 */
JRM1986 22:7f81fca01f02 28
JRM1986 19:b437806e579b 29 void init(Direction in, Direction cur, int pos_x, int pos_y);
JRM1986 13:72bc2579e85e 30
JRM1986 22:7f81fca01f02 31 /** Updates methods for snake head
JRM1986 23:3081be418c89 32 * @param Input direction from pad
JRM1986 23:3081be418c89 33 * @param Current direction of snake
JRM1986 22:7f81fca01f02 34 */
JRM1986 22:7f81fca01f02 35
JRM1986 10:62d8cb7742c3 36 void update(Direction in, Direction cur);
JRM1986 22:7f81fca01f02 37
JRM1986 22:7f81fca01f02 38 /** Draws snake head on lcd */
JRM1986 22:7f81fca01f02 39
JRM1986 9:561e5681b7a6 40 void draw(N5110 &lcd);
JRM1986 9:561e5681b7a6 41
JRM1986 22:7f81fca01f02 42 /** Gives the next direction of the snake
JRM1986 23:3081be418c89 43 * @brief Gives the next direction given the current and input directions
JRM1986 23:3081be418c89 44 * @param Input direction from pad
JRM1986 23:3081be418c89 45 * @param Current direction of snake
JRM1986 22:7f81fca01f02 46 */
JRM1986 22:7f81fca01f02 47
JRM1986 10:62d8cb7742c3 48 void set_snake_direction(Direction input, Direction current);
JRM1986 22:7f81fca01f02 49
JRM1986 22:7f81fca01f02 50 /** Determines the possible next directions for the current direction CENTRE
JRM1986 23:3081be418c89 51 * @brief can be any direction except Centre
JRM1986 23:3081be418c89 52 * @param Input direction from pad
JRM1986 23:3081be418c89 53 * @param Current direction of snake
JRM1986 22:7f81fca01f02 54 */
JRM1986 22:7f81fca01f02 55
JRM1986 22:7f81fca01f02 56 void set_centre(Direction input, Direction current);
JRM1986 22:7f81fca01f02 57
JRM1986 22:7f81fca01f02 58 /** Determines the possible next directions for the current direction North
JRM1986 23:3081be418c89 59 * @brief Cannot be South
JRM1986 23:3081be418c89 60 * @param Input direction from pad
JRM1986 23:3081be418c89 61 * @param Current direction of snake
JRM1986 22:7f81fca01f02 62 */
JRM1986 22:7f81fca01f02 63
JRM1986 19:b437806e579b 64 void set_north(Direction input, Direction current);
JRM1986 22:7f81fca01f02 65
JRM1986 22:7f81fca01f02 66 /** Determines the possible next directions for the current direction East
JRM1986 23:3081be418c89 67 * @brief Cannot be West
JRM1986 23:3081be418c89 68 * @param Input direction from pad
JRM1986 23:3081be418c89 69 * @param Current direction of snake
JRM1986 22:7f81fca01f02 70 */
JRM1986 22:7f81fca01f02 71
JRM1986 19:b437806e579b 72 void set_east(Direction input, Direction current);
JRM1986 22:7f81fca01f02 73
JRM1986 22:7f81fca01f02 74 /** Determines the possible next directions for the current direction South
JRM1986 23:3081be418c89 75 * @brief Cannot be North
JRM1986 23:3081be418c89 76 * @param Input direction from pad
JRM1986 23:3081be418c89 77 * @param Current direction of snake
JRM1986 22:7f81fca01f02 78 */
JRM1986 22:7f81fca01f02 79
JRM1986 19:b437806e579b 80 void set_south(Direction input, Direction current);
JRM1986 22:7f81fca01f02 81
JRM1986 22:7f81fca01f02 82 /** Determines the possible next directions for the current direction West
JRM1986 23:3081be418c89 83 * @brief Cannot be East
JRM1986 23:3081be418c89 84 * @param Input direction from pad
JRM1986 23:3081be418c89 85 * @param Current direction of snake
JRM1986 22:7f81fca01f02 86 */
JRM1986 22:7f81fca01f02 87
JRM1986 19:b437806e579b 88 void set_west(Direction input, Direction current);
JRM1986 19:b437806e579b 89
JRM1986 22:7f81fca01f02 90 /** Gets snake direction
JRM1986 23:3081be418c89 91 * @return returns next direction of the snake head
JRM1986 22:7f81fca01f02 92 */
JRM1986 22:7f81fca01f02 93
JRM1986 9:561e5681b7a6 94 Direction get_snake_direction();
JRM1986 13:72bc2579e85e 95
JRM1986 22:7f81fca01f02 96 /** Sets the current direction such that it is never CENTRE
JRM1986 23:3081be418c89 97 * @param Input direction from pad
JRM1986 22:7f81fca01f02 98 */
JRM1986 22:7f81fca01f02 99
JRM1986 14:c3a435597196 100 void set_current_direction(Direction input);
JRM1986 22:7f81fca01f02 101
JRM1986 22:7f81fca01f02 102 /** Gets current direction
JRM1986 23:3081be418c89 103 * @return returns current direction
JRM1986 22:7f81fca01f02 104 */
JRM1986 22:7f81fca01f02 105
JRM1986 11:e260c17a0489 106 Direction get_current_direction();
JRM1986 13:72bc2579e85e 107
JRM1986 22:7f81fca01f02 108 /** Given the next direction increments the snake's position appropriatley
JRM1986 23:3081be418c89 109 * @param Next direction from get_direction
JRM1986 23:3081be418c89 110 */
JRM1986 22:7f81fca01f02 111
JRM1986 10:62d8cb7742c3 112 void set_snake_position(Direction next);
JRM1986 22:7f81fca01f02 113
JRM1986 22:7f81fca01f02 114 /** Gets updated position
JRM1986 23:3081be418c89 115 * @return returns new position
JRM1986 22:7f81fca01f02 116 */
JRM1986 22:7f81fca01f02 117
JRM1986 9:561e5681b7a6 118 Vector2D get_snake_position();
JRM1986 14:c3a435597196 119
JRM1986 14:c3a435597196 120
JRM1986 2:ea90cec2489a 121
JRM1986 2:ea90cec2489a 122 private:
JRM1986 9:561e5681b7a6 123
JRM1986 10:62d8cb7742c3 124 Direction _next;
JRM1986 13:72bc2579e85e 125 Direction _current;
JRM1986 21:63c5590cb2c2 126 Direction _d;
JRM1986 13:72bc2579e85e 127 Vector2D _pos;
JRM1986 9:561e5681b7a6 128
JRM1986 2:ea90cec2489a 129 };
JRM1986 2:ea90cec2489a 130 #endif