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.
Engine.h
00001 #include "mbed.h" 00002 #include "N5110.h" 00003 #include "Gamepad.h" 00004 #include "Snek.h" 00005 #include "Food.h" 00006 00007 /** The Game Engine class 00008 * @brief Handles all failure states and game drawing 00009 * @author Andrew J. Moore 00010 * @date May, 2018 00011 */ 00012 00013 class Engine 00014 { 00015 00016 public: 00017 00018 /** Constructor */ 00019 Engine(); 00020 00021 /** Destructor */ 00022 ~Engine(); 00023 00024 /** Initialisation function */ 00025 void init(); 00026 00027 /** Reads and stores the current inputs from the gamepad 00028 * @param the current state of the gamepad (Gamepad) 00029 */ 00030 void read_input(Gamepad &pad); 00031 00032 /** Updates the current game state 00033 * @param the gamepad's functions as it is needed to use the speaker (Gamepad) 00034 */ 00035 void update(Gamepad &pad); 00036 00037 /** Draws the current state of the game 00038 * @param the LCD so that it can be drawn to (N5110) 00039 */ 00040 void draw(N5110 &lcd); 00041 00042 /** Applies a splash screen to signify a game over state has been reached 00043 * @param the LCD so that it can be drawn to (N5110) 00044 */ 00045 void gameOverScreen(N5110 &lcd); 00046 00047 /** Gets the current score 00048 * @return the current score 00049 */ 00050 float getScore(); 00051 00052 /** Gets the current game state 00053 * @return the value of _gameOver 00054 */ 00055 bool getGameOver(); 00056 00057 /** Sets the current level 00058 * @param the level to be set to (int) 00059 */ 00060 void setLvl(int _levelToSet); 00061 00062 private: 00063 00064 //Private Variables 00065 int _score; 00066 Direction _d; 00067 int _grid[22][22]; 00068 Snek _solid; //Named after Metal Gear Solid character Solid Snake to reduce confusion when debugging 00069 Food _noodles; //Common foodstuffs in MGS, once again to reduce confusion 00070 bool _gameOver; 00071 int _lvl; 00072 00073 //Private Methods 00074 string convertString(int a); 00075 void loadLvl(); 00076 void lvlOne(); 00077 void lvlTwo(); 00078 void lvlThree(); 00079 bool checkFood(); 00080 void growSnake(); 00081 void checkGameOverAndSetGrid(); 00082 00083 //Testing Methods 00084 void gameTest(); 00085 bool snakeTest(); 00086 bool foodTest(); 00087 };
Generated on Sun Jul 17 2022 04:24:16 by
1.7.2