Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
snake.h
00001 00002 #ifndef SNAKE_H 00003 #define SNAKE_H 00004 00005 #include "mbed.h" 00006 #include "N5110.h" 00007 #include "Gamepad.h" 00008 00009 /** Snake Class 00010 * Owen Cavender, University of Leeds 00011 */ 00012 00013 class Snake 00014 { 00015 00016 00017 public: 00018 Snake(); 00019 /** constructor 00020 */ 00021 ~Snake(); 00022 /** deconstructor 00023 */ 00024 00025 enum Directions { /**enum of directions*/ 00026 up, 00027 down, 00028 left, 00029 right, 00030 00031 }; 00032 00033 void init(); 00034 /** initialises 'Snake' class 00035 */ 00036 void get_direction(Gamepad &pad); 00037 /** reads input from gamepad 00038 *updates direction 00039 */ 00040 void render_clear_tail(N5110 &lcd); 00041 /** clears pixel on the end of snake 00042 *before everything else on the screen is updated and rendered 00043 */ 00044 void move_snake(); 00045 /**alters the values assigned to the snake's body 00046 *based on the _direction set in get_direction 00047 */ 00048 void apple_collected(N5110 &lcd, Gamepad &pad); 00049 /** check to see if the apple x,y = snakehead x,y values 00050 *increases score, triggers a true which causes generation of apple, updates counter 00051 *Plays a tone and toggles LEDs 00052 */ 00053 void check_gameover(N5110 &lcd); 00054 /**checks if game is over based on 3 conditions 00055 */ 00056 void get_Apple_position(N5110 &lcd); 00057 /**sets the apple position 00058 *an update of position is triggered by bool _reset_apple 00059 */ 00060 void render(N5110 &lcd, Gamepad &pad); 00061 /**draws the snake, border, and apple during the game 00062 * if it is game over, it displays the score and a gameo over message 00063 */ 00064 00065 00066 00067 Vector2D get_Snakehead(); 00068 /**returns _x0, and _y0 values 00069 */ 00070 00071 int get_countdown(); 00072 /**reurns counter value 00073 */ 00074 int get_score(); 00075 /**returns score; 00076 */ 00077 00078 private: 00079 00080 00081 bool get_gameover(); 00082 /** returns _gameover 00083 *private as it is only used in Snake class 00084 */ 00085 00086 /**Snake private variables*/ 00087 Directions _direction; 00088 int _countdown; 00089 bool _gameover; 00090 int _score; 00091 int _reset_apple; 00092 00093 int _x0; /**snake position variable*/ 00094 int _y0; 00095 int _x1; 00096 int _y1; 00097 int _x2; 00098 int _y2; 00099 int _x3; 00100 int _y3; 00101 int _x4; 00102 int _y4; 00103 int _x5; 00104 int _y5; 00105 int _x6; 00106 int _y6; 00107 int _x7; 00108 int _y7; 00109 00110 00111 int _apx; /**apple position variable*/ 00112 int _apy; 00113 00114 }; 00115 00116 00117 #endif
Generated on Wed Jul 20 2022 02:14:09 by
