/** * * @file game.h * @author RUBINI Thomas * @author SIMAILA Djalim * @date January 2022 * @version 1.0 * @brief full game logic and display management * **/ #ifndef GUARD_GAME_H #define GUARD_GAME_H #include #include "mingl/mingl.h" #include "pixelManager/pixelManager.h" #include "utils.h" #include "playerDef.h" #include "player.h" #include "playMode.h" #include "configData.h" #include "projectiles.h" #include "scoresManager.h" #include "god.h" #include "invadersGrid.h" using namespace std; /*! * @class Game * @brief Main game class */ class Game { private: /*! * @brief the MinGL window in which the game will be drawn into */ MinGL window; /*! * @brief PixelManager : Class that contains and draws all the data that will be drawn on screen * This is a pointer because the object is allocated at runtime, following the configuration */ unique_ptr pm; /*! * @brief ConfigData : Struct that stores all the relevant data read from the configuration file */ ConfigData confData; /*! * @brief ScoresManager : utility to handle score saving and signing */ ScoresManager sm; /*! * @brief Special entity : God */ God god; /*! * @brief base position for game display */ Position basePos; /*! * @brief Invader position and type matrix */ InvadersGrid grid; /*! * @brief Invader scroll direction - True = right , False = left */ bool direction; /*! * @brief list of postion of all missiles shot by the invaders */ vector missiles; /*! * @brief list of postion of all torpedos shot by the player(s) */ vector torpedos; /*! * @brief Define the current type of the game */ PlayMode playMode; /*! * @brief list of all player data */ vector players; // invaders related variables /*! * @brief cooldown until the invaders can shoot again */ unsigned fireCooldown=0; // basic methods /*! * @brief Set or reset all the setting for a new game * @fn void initGame(); */ void initGame(); /*! * @brief * @return true if there are no more invaders in the grid * @fn bool updateColumns(); */ bool areThereInvadersLeft(); /*! * @brief Asks the player(s) name(s) and write their score to the score file * @fn void handleScoreSaving(); */ void handleScoreSaving(); /*! * @brief convert invader's matrix position to pixel coodinates * @return pixel position object * @fn Position invIndexToPos(unsigned x, unsigned y) const; */ Position invIndexToPos(unsigned x, unsigned y) const; // drawing methods /*! * @brief display players score on the screen * @fn void displayScore(); */ void displayScore() const; /*! * @brief main display function, clear the window and calls sub display functions * @param[in] fps : current screen refresh rate * @fn void displayAll() const; */ void displayAll(unsigned fps) const; /*! * @brief display God related objets * @fn void displayGod() const; */ void displayGod() const; /*! * @brief display a singular invader * @param[in] basePos : invader's pixel coordinates * @param[in] type : invader's type * @fn void displayInvader(const Position& basePos, InvaderType type) const */ void displayInvader(const Position& basePos, InvaderType type) const; /*! * @brief displays a player's remaining lives * @fn void displayHearts(playerID) const; */ void displayHearts(playerID) const; // managers /*! * @brief Calls the function 'ManageOnePlayer' for all players in player list * @fn void managePlayers(); */ void managePlayers(); /*! * @brief Handles a player keystrokes, makes them move or make them shoot a torpedo * @param[in] pID : Player id * @fn void manageOnePlayer(playerID pID); */ void manageOnePlayer(playerID pID); /*! * @brief Handles all invaders movements and when they'll shoot a missile * @return true if the invaders went down from one line (and we should check lower boundary), else false * @fn bool manageInvaders(); */ bool manageInvaders(); // collision things /*! * @brief Removes torpedo and missiles that are colliding * @fn void remCollidingProjectiles(); */ void remCollidingProjectiles(); /*! * @brief Makes all missiles go downward * @fn void moveMissiles(); */ void moveMissiles(); /*! * @brief Makes all torpedos go upward * @fn void moveTorpedos(); */ void moveTorpedos(); /*! * @brief checks if a missile collides with a player * @fn checkMissilesAndPlayers(); */ void checkMissilesAndPlayers(); /*! * @brief check if a torpedo collides with an invader * @return true if there is a collision, false elsewise * @fn bool checkTorpedosAndInvaders(); */ bool checkTorpedosAndInvaders(); /*! * @brief check if the invaders have reach the players * @return true if they have reach the player, false elsewise * @fn bool invadersTouchPlayer() const; */ bool invadersTouchPlayer() const; /*! * @brief Try to awake god, if not already awaken * @fn void tryAwakeGod(); */ void tryAwakeGod(); /*! * @brief make god behave * @return true if theres no invader left, false elsewise * @fn bool manageGod(); */ bool manageGod(); public: // in case someone wants to mess with the code, here's a minimal API, costs nothing to us /*! * @brief constructor for the game class * @fn Game(); */ Game(); /*! * @brief manages and changes the states of the game * @fn void managedGames(); */ void managedGames(); /*! * @brief enter the main gameplay game loop * @return the value of the winners can be the players, the invaders or god * @fn WinValue enterGameLoop(); */ WinValue enterGameLoop(); /*! * @brief reload the configuration file for a new game * @return false if an error occured, true elsewise * @fn bool reloadConfig(); */ bool reloadConfig(); /*! * @brief tells if all players are dead * @return true if all player are dead, false otherwise * @fn bool arePlayersDead(); */ bool arePlayersDead(); }; #endif