Final Commit

Dependencies:   mbed

Committer:
JRM1986
Date:
Tue May 01 10:55:49 2018 +0000
Revision:
23:3081be418c89
Parent:
22:7f81fca01f02
Child:
26:23301f48c1ed
Comments in process;

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