From 7b2eda8549a1a9f5227c8aa5480de7419956e860 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 9 Jan 2022 16:44:53 +0100 Subject: [PATCH] things --- headers/pixelManager.h | 76 ++++++++++++++++++++++++++++------------- headers/scoresManager.h | 4 +-- headers/utils.h | 10 ++++++ src/main.cpp | 4 ++- src/scoresManager.cpp | 12 ++++--- 5 files changed, 74 insertions(+), 32 deletions(-) diff --git a/headers/pixelManager.h b/headers/pixelManager.h index 94a47f2..85f4e47 100644 --- a/headers/pixelManager.h +++ b/headers/pixelManager.h @@ -80,50 +80,56 @@ public: explicit PixelManager(MinGL&); /*! - * @brief - * @param[in] baseVector : - * @param[in] size : - * @param[in] color : - * @fn + * @brief display a type A invader on screen + * @param[in] baseVector : pixel coordinate of the invader + * @param[in] size : size multiplicator of the invader + * @param[in] color : color multiplicaror of the invader + * @fn void drawInvaderA(const Position& baseVector, unsigned size, const RGBAcolor& color) const; */ void drawInvaderA(const Position& baseVector, unsigned size, const RGBAcolor& color) const; /*! - * @brief - * @param[in] baseVector : - * @param[in] size : - * @param[in] color : - * @fn + * @brief display a type B invader on screen + * @param[in] baseVector : pixel coordinate of the invader + * @param[in] size : size multiplicator of the invader + * @param[in] color : color multiplicaror of the invader + * @fn void drawInvaderB(const Position& baseVector, unsigned size, const RGBAcolor& color) const; */ void drawInvaderB(const Position& baseVector, unsigned size, const RGBAcolor& color) const; /*! - * @brief - * @param[in] baseVector - * @param[in] size - * @param[in] color - * @fn + * @brief display a type C invader on screen + * @param[in] baseVector : pixel coordinate of the invader + * @param[in] size : size multiplicator of the invader + * @param[in] color : color multiplicaror of the invader + * @fn void drawInvaderC(const Position& baseVector, unsigned size, const RGBAcolor& color) const; */ void drawInvaderC(const Position& baseVector, unsigned size, const RGBAcolor& color) const; /*! - * @brief - * @param[] - * @fn + * @brief display a player on screen + * @param[in] x : horizontal position of the player + * @param[in] witdh : width of the player + * @param[in] color : color of the plater + * @fn void drawPlayer(unsigned x, unsigned width, const nsGraphics::RGBAcolor& color) const; */ void drawPlayer(unsigned x, unsigned width, const nsGraphics::RGBAcolor& color) const; /*! - * @brief - * @param[] - * @fn + * @brief display a missile on screen + * @param[in] baseVector : pixel coordinates of the missile + * @param[in] width : width of the missle + * @param[in] color : color of the missile + * @fn void drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const; */ void drawMissile(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const; /*! - * @brief - * @param[] - * @fn + * @brief display a torpedo on screen + * @param[in] baseVector : pixel coordinates of the torpedo + * @param[in] width : width of the torpedo + * @param[in] color : color of the torpedo + * @fn void drawTorpedo(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const; */ void drawTorpedo(const Position& baseVector, unsigned width, const nsGraphics::RGBAcolor& color) const; @@ -171,10 +177,32 @@ public: */ void drawFPS(unsigned fps) const; + /*! + * @brief + * @return + * @fn + */ PlayMode showInitialMenu(); + + /*! + * @brief + * @return + * @fn + */ bool showDeathMenu(); + /*! + * @brief + * @return + * @fn + */ unsigned getScreenHeight() const; + + /*! + * @brief + * @return + * @fn + */ unsigned getScreenWidth() const; /*! diff --git a/headers/scoresManager.h b/headers/scoresManager.h index d8d4460..a353d87 100644 --- a/headers/scoresManager.h +++ b/headers/scoresManager.h @@ -21,13 +21,13 @@ using namespace std; struct ScoreLink{ string name; unsigned score; - ScoreLink(string&& name, unsigned score); + ScoreLink(string name, unsigned score); }; class ScoresManager { public: vector scores; - void inputScore(string&& name, unsigned score); + void inputScore(string name, unsigned score); void readFile(); void writeFile() const; }; diff --git a/headers/utils.h b/headers/utils.h index aa28428..eb7915b 100644 --- a/headers/utils.h +++ b/headers/utils.h @@ -14,6 +14,16 @@ * (We need to explicitly specify the default constructor)*/ #define INV_GET_POS(i) confData.invadersSize*(i)+confData.invadersDistance*(i) +// Syntax : DEBUG(cout << "hey" << endl) +// The debug flag defintion has been set here, but normally we would add it to the MakeFile +#define DEBUG_FLAG + +#ifdef DEBUG_FLAG +#define DEBUG(X) X; +#else +#define DEBUG(X) +#endif + using namespace std; using nsGraphics::RGBAcolor; diff --git a/src/main.cpp b/src/main.cpp index a2d7d07..52e01c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,10 +18,12 @@ using namespace std; // TODO changer tout les unsigned par des size_t dans les boucles int main(){ + DEBUG(cout << "Starting program" << endl) srand(time(NULL)); - + Game g; g.managedGames(); + DEBUG(cout << "Finished program. Goodbye !" << endl) return 0; } \ No newline at end of file diff --git a/src/scoresManager.cpp b/src/scoresManager.cpp index a42d3f4..d27532d 100644 --- a/src/scoresManager.cpp +++ b/src/scoresManager.cpp @@ -86,21 +86,23 @@ void ScoresManager::writeFile() const { /** * Insertion sort, probably the most efficient here */ -void ScoresManager::inputScore(string&& name, unsigned score) { +void ScoresManager::inputScore(string name, unsigned score) { auto ite = scores.begin(); while(ite!=scores.end()){ if(score > ite->score) { - scores.emplace(ite, name, score); + scores.emplace(ite, move(name), score); break; } ++ite; } - if(ite==scores.end())scores.emplace(ite, name, score); + + if(ite==scores.end())scores.emplace(ite, move(name), score); + if(scores.size()>SCORE_LIMIT)scores.erase(scores.begin()+SCORE_LIMIT); } -ScoreLink::ScoreLink(string&& name, unsigned int score) { - this->name = name; +ScoreLink::ScoreLink(string name, unsigned int score) { + this->name = move(name); this->score = score; }