ELEC2645 (2017/18) / Mbed 2 deprecated ll13jrm

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Snake.h Source File

Snake.h

00001 #ifndef SNAKE_H
00002 #define SNAKE_H
00003 
00004 #include "mbed.h"
00005 #include "Gamepad.h"
00006 #include "N5110.h"
00007 
00008 /** Snake Class
00009 * @brief Describes the methods and functions for the snake head
00010 * @author Joshua R. Marshall
00011 * @date Feb, 2018
00012 */
00013 
00014 class Snake
00015 {
00016 
00017 public:
00018 
00019     Snake(); // constructor
00020     ~Snake(); // destructor
00021     
00022     /** Initialises the snakes direction and position when game starts 
00023     * @param Input direction from pad
00024     * @param Current direction of snake
00025     * @param pos_x x position
00026     * @param pos_y y position 
00027     */
00028     
00029     void init(Direction in, Direction cur, int pos_x, int pos_y);
00030     
00031     /** Updates methods for snake head
00032     * @param Input direction from pad
00033     * @param Current direction of snake
00034     */
00035     
00036     void update(Direction in, Direction cur);
00037     
00038     /** Draws snake head on lcd */
00039     
00040     void draw(N5110 &lcd);
00041     
00042     /** Gives the next direction of the snake
00043     * @brief Gives the next direction given the current and input directions
00044     * @param Input direction from pad
00045     * @param Current direction of snake
00046     */
00047     
00048     void set_snake_direction(Direction input, Direction current);
00049     
00050     /** Determines the possible next directions for the current direction CENTRE
00051     * @brief can be any direction except Centre
00052     * @param Input direction from pad
00053     * @param Current direction of snake
00054     */
00055     
00056     void set_centre(Direction input, Direction current);
00057     
00058     /** Determines the possible next directions for the current direction North
00059     * @brief Cannot be South
00060     * @param Input direction from pad
00061     * @param Current direction of snake
00062     */
00063     
00064     void set_north(Direction input, Direction current);
00065     
00066     /** Determines the possible next directions for the current direction East
00067     * @brief Cannot be West
00068     * @param Input direction from pad
00069     * @param Current direction of snake
00070     */
00071    
00072     void set_east(Direction input, Direction current);
00073   
00074     /** Determines the possible next directions for the current direction South
00075     * @brief Cannot be North
00076     * @param Input direction from pad
00077     * @param Current direction of snake
00078     */    
00079   
00080     void set_south(Direction input, Direction current);
00081   
00082     /** Determines the possible next directions for the current direction West
00083     * @brief Cannot be East
00084     * @param Input direction from pad
00085     * @param Current direction of snake
00086     */    
00087   
00088     void set_west(Direction input, Direction current);
00089     
00090     /** Gets snake direction
00091     * @return returns next direction of the snake head
00092     */
00093     
00094     Direction get_snake_direction();
00095     
00096     /** Sets the current direction such that it is never CENTRE
00097     * @param Input direction from pad
00098     */
00099     
00100     void set_current_direction(Direction input);
00101     
00102     /** Gets current direction
00103     * @return returns current direction
00104     */
00105     
00106     Direction get_current_direction();
00107     
00108     /** Given the next direction increments the snake's position appropriatley
00109     * @param Next direction from get_direction 
00110     */
00111     
00112     void set_snake_position(Direction next);
00113     
00114     /** Gets updated position
00115     * @return returns new position
00116     */
00117     
00118     Vector2D get_snake_position();
00119     
00120     
00121 
00122 private:
00123     
00124     Direction _next;
00125     Direction _current;
00126     Direction _d;
00127     Vector2D _pos;
00128     
00129 };
00130 #endif