diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index 63c2a97..04b0f33 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp @@ -251,6 +251,15 @@ bool BlockGame::GetIsWinner() const { return hasWonTheGame; } + +void BlockGame::NewGame(const BlockGameStartInfo &s) { + NewGame(s.ticks); + if (s.timeTrial) { + timetrial = true; + putStartBlocks(); + } +} + //Instead of creating new object new game is called, to prevent memory leaks void BlockGame::NewGame( unsigned int ticks) { this->ticks = ticks; @@ -292,12 +301,6 @@ void BlockGame::NewGame( unsigned int ticks) { lastAImove = ticks+3000; } //NewGame -void BlockGame::NewTimeTrialGame( unsigned int ticks) { - NewGame(ticks); - timetrial = true; - putStartBlocks(); -} - //Starts a new stage game, takes level as input! void BlockGame::NewStageGame(int level, unsigned int ticks) { if (level > -1) { diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index 3741417..6bcad28 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp @@ -56,6 +56,14 @@ extern stageButton stageButtonStatus; //This is the size of the blocks. They are always 50. The internal logic calculates it that way const int bsize = 50; +/** + * This struct defines the start conditions of the game + */ +struct BlockGameStartInfo { + unsigned int ticks = 0; + bool timeTrial = false; +}; + //////////////////////////////////////////////////////////////////////////////// //The BloackGame class represents a board, score, time etc. for a single player/ //////////////////////////////////////////////////////////////////////////////// @@ -171,9 +179,7 @@ public: int GetCursorY() const; void MoveCursorTo(int x, int y); bool GetIsWinner() const; - //Instead of creating new object new game is called, to prevent memory leaks - void NewGame(unsigned int ticks); - void NewTimeTrialGame(unsigned int ticks); + void NewGame(const BlockGameStartInfo &s); //Starts a new stage game, takes level as input! void NewStageGame(int level, unsigned int ticks); void NewPuzzleGame(int level, unsigned int ticks); @@ -217,6 +223,7 @@ public: bool isSinglePuzzle() const; int getLevel() const; private: + void NewGame(unsigned int ticks); //Test if LineNr is an empty line, returns false otherwise. bool LineEmpty(int lineNr) const; //Test if the entire board is empty (used for Puzzles) diff --git a/source/code/main.cpp b/source/code/main.cpp index b6c649c..9e25b2d 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -1478,7 +1478,9 @@ static bool registerTTHighscorePlayer2 = false; static void StartSinglePlayerEndless() { //1 player - endless - player1->NewGame(SDL_GetTicks()); + BlockGameStartInfo startInfo; + startInfo.ticks = SDL_GetTicks(); + player1->NewGame(startInfo); player1->putStartBlocks(time(0)); twoPlayers =false; player2->SetGameOver(); @@ -1488,7 +1490,10 @@ static void StartSinglePlayerEndless() { } static void StartSinglePlayerTimeTrial() { - player1->NewTimeTrialGame(SDL_GetTicks()); + BlockGameStartInfo startInfo; + startInfo.ticks = SDL_GetTicks(); + startInfo.timeTrial = true; + player1->NewGame(startInfo); twoPlayers =false; player2->SetGameOver(); //vsMode = false; @@ -1514,8 +1519,11 @@ static int StartSinglePlayerPuzzle(int level) { static void StarTwoPlayerTimeTrial() { - player1->NewTimeTrialGame(SDL_GetTicks()); - player2->NewTimeTrialGame(SDL_GetTicks()); + BlockGameStartInfo startInfo; + startInfo.ticks = SDL_GetTicks(); + startInfo.timeTrial = true; + player1->NewGame(startInfo); + player2->NewGame(startInfo); int theTime = time(0); player1->putStartBlocks(theTime); player2->putStartBlocks(theTime);