Final Commit

Dependencies:   mbed

Committer:
JRM1986
Date:
Tue May 01 09:44:53 2018 +0000
Revision:
22:7f81fca01f02
Parent:
21:63c5590cb2c2
Child:
23:3081be418c89
Comments for Snake and Food Classes complete;

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 22:7f81fca01f02 24 @param Input direction from pad
JRM1986 22:7f81fca01f02 25 @param Current of snake
JRM1986 22:7f81fca01f02 26 @param pos_x x position
JRM1986 22:7f81fca01f02 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 22:7f81fca01f02 33 @param Input direction from pad
JRM1986 22:7f81fca01f02 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 22:7f81fca01f02 44 @brief Gives the next direction given the current and input directions
JRM1986 22:7f81fca01f02 45 @param Input direction from pad
JRM1986 22:7f81fca01f02 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 22:7f81fca01f02 52 @brief can be any direction except Centre
JRM1986 22:7f81fca01f02 53 @param Input direction from pad
JRM1986 22:7f81fca01f02 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 22:7f81fca01f02 60 @brief Cannot be South
JRM1986 22:7f81fca01f02 61 @param Input direction from pad
JRM1986 22:7f81fca01f02 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 22:7f81fca01f02 68 @brief Cannot be West
JRM1986 22:7f81fca01f02 69 @param Input direction from pad
JRM1986 22:7f81fca01f02 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 22:7f81fca01f02 76 @brief Cannot be North
JRM1986 22:7f81fca01f02 77 @param Input direction from pad
JRM1986 22:7f81fca01f02 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 22:7f81fca01f02 84 @brief Cannot be East
JRM1986 22:7f81fca01f02 85 @param Input direction from pad
JRM1986 22:7f81fca01f02 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 22:7f81fca01f02 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 22:7f81fca01f02 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 22:7f81fca01f02 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 22:7f81fca01f02 110 @param Next direction from get_direction */
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 22:7f81fca01f02 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