ELEC2645 (2017/18) / Mbed OS el16ajm
Committer:
Andrew_M
Date:
Tue May 08 14:41:56 2018 +0000
Revision:
16:4d329ce7b156
Parent:
15:130900e5c268
Added testing functions, found and fixed an error in the food placement (double Y cor not X and Y)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Andrew_M 1:a14415de3ad5 1 #include "mbed.h"
Andrew_M 1:a14415de3ad5 2 #include "N5110.h"
Andrew_M 1:a14415de3ad5 3 #include "Gamepad.h"
Andrew_M 1:a14415de3ad5 4 #include "Snek.h"
Andrew_M 5:a3a9e0417e04 5 #include "Food.h"
Andrew_M 1:a14415de3ad5 6
Andrew_M 14:a57a40ff9430 7 /** The Game Engine class
Andrew_M 14:a57a40ff9430 8 * @brief Handles all failure states and game drawing
Andrew_M 14:a57a40ff9430 9 * @author Andrew J. Moore
Andrew_M 14:a57a40ff9430 10 * @date May, 2018
Andrew_M 14:a57a40ff9430 11 */
Andrew_M 14:a57a40ff9430 12
Andrew_M 1:a14415de3ad5 13 class Engine
Andrew_M 1:a14415de3ad5 14 {
Andrew_M 1:a14415de3ad5 15
Andrew_M 1:a14415de3ad5 16 public:
Andrew_M 14:a57a40ff9430 17
Andrew_M 14:a57a40ff9430 18 /** Constructor */
Andrew_M 1:a14415de3ad5 19 Engine();
Andrew_M 14:a57a40ff9430 20
Andrew_M 14:a57a40ff9430 21 /** Destructor */
Andrew_M 1:a14415de3ad5 22 ~Engine();
Andrew_M 1:a14415de3ad5 23
Andrew_M 15:130900e5c268 24 /** Initialisation function */
Andrew_M 1:a14415de3ad5 25 void init();
Andrew_M 14:a57a40ff9430 26
Andrew_M 14:a57a40ff9430 27 /** Reads and stores the current inputs from the gamepad
Andrew_M 14:a57a40ff9430 28 * @param the current state of the gamepad (Gamepad)
Andrew_M 14:a57a40ff9430 29 */
Andrew_M 1:a14415de3ad5 30 void read_input(Gamepad &pad);
Andrew_M 14:a57a40ff9430 31
Andrew_M 14:a57a40ff9430 32 /** Updates the current game state
Andrew_M 14:a57a40ff9430 33 * @param the gamepad's functions as it is needed to use the speaker (Gamepad)
Andrew_M 14:a57a40ff9430 34 */
Andrew_M 1:a14415de3ad5 35 void update(Gamepad &pad);
Andrew_M 14:a57a40ff9430 36
Andrew_M 14:a57a40ff9430 37 /** Draws the current state of the game
Andrew_M 14:a57a40ff9430 38 * @param the LCD so that it can be drawn to (N5110)
Andrew_M 14:a57a40ff9430 39 */
Andrew_M 1:a14415de3ad5 40 void draw(N5110 &lcd);
Andrew_M 14:a57a40ff9430 41
Andrew_M 14:a57a40ff9430 42 /** Applies a splash screen to signify a game over state has been reached
Andrew_M 14:a57a40ff9430 43 * @param the LCD so that it can be drawn to (N5110)
Andrew_M 14:a57a40ff9430 44 */
Andrew_M 12:d3eef5ea3f43 45 void gameOverScreen(N5110 &lcd);
Andrew_M 14:a57a40ff9430 46
Andrew_M 14:a57a40ff9430 47 /** Gets the current score
Andrew_M 14:a57a40ff9430 48 * @return the current score
Andrew_M 14:a57a40ff9430 49 */
Andrew_M 13:81573be8fac6 50 float getScore();
Andrew_M 14:a57a40ff9430 51
Andrew_M 14:a57a40ff9430 52 /** Gets the current game state
Andrew_M 14:a57a40ff9430 53 * @return the value of _gameOver
Andrew_M 14:a57a40ff9430 54 */
Andrew_M 14:a57a40ff9430 55 bool getGameOver();
Andrew_M 14:a57a40ff9430 56
Andrew_M 14:a57a40ff9430 57 /** Sets the current level
Andrew_M 14:a57a40ff9430 58 * @param the level to be set to (int)
Andrew_M 14:a57a40ff9430 59 */
Andrew_M 12:d3eef5ea3f43 60 void setLvl(int _levelToSet);
Andrew_M 5:a3a9e0417e04 61
Andrew_M 1:a14415de3ad5 62 private:
Andrew_M 5:a3a9e0417e04 63
Andrew_M 14:a57a40ff9430 64 //Private Variables
Andrew_M 5:a3a9e0417e04 65 int _score;
Andrew_M 1:a14415de3ad5 66 Direction _d;
Andrew_M 2:9ca5e1c221c3 67 int _grid[22][22];
Andrew_M 12:d3eef5ea3f43 68 Snek _solid; //Named after Metal Gear Solid character Solid Snake to reduce confusion when debugging
Andrew_M 12:d3eef5ea3f43 69 Food _noodles; //Common foodstuffs in MGS, once again to reduce confusion
Andrew_M 5:a3a9e0417e04 70 bool _gameOver;
Andrew_M 12:d3eef5ea3f43 71 int _lvl;
Andrew_M 14:a57a40ff9430 72
Andrew_M 13:81573be8fac6 73 //Private Methods
Andrew_M 14:a57a40ff9430 74 string convertString(int a);
Andrew_M 13:81573be8fac6 75 void loadLvl();
Andrew_M 13:81573be8fac6 76 void lvlOne();
Andrew_M 13:81573be8fac6 77 void lvlTwo();
Andrew_M 14:a57a40ff9430 78 void lvlThree();
Andrew_M 13:81573be8fac6 79 bool checkFood();
Andrew_M 15:130900e5c268 80 void growSnake();
Andrew_M 14:a57a40ff9430 81 void checkGameOverAndSetGrid();
Andrew_M 16:4d329ce7b156 82
Andrew_M 16:4d329ce7b156 83 //Testing Methods
Andrew_M 16:4d329ce7b156 84 void gameTest();
Andrew_M 16:4d329ce7b156 85 bool snakeTest();
Andrew_M 16:4d329ce7b156 86 bool foodTest();
Andrew_M 1:a14415de3ad5 87 };