diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index 726e1f6..156f5a0 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp @@ -302,6 +302,17 @@ void BlockGame::NewGame(const BlockGameStartInfo &s) { } } } + if (s.vsMode) { + vsMode = true; + AI_Enabled = s.AI; + if (!AI_Enabled) { + Stats::getInstance()->addOne("VSgamesStarted"); + } + else { + name = "CPU"; + } + putStartBlocks(); + } } //Instead of creating new object new game is called, to prevent memory leaks @@ -345,29 +356,6 @@ void BlockGame::NewGame( unsigned int ticks) { lastAImove = ticks+3000; } //NewGame -//Starts new Vs Game (two Player) -void BlockGame::NewVsGame(BlockGame* target, unsigned int ticks) { - NewGame(ticks); - vsMode = true; - putStartBlocks(); - garbageTarget = target; - Stats::getInstance()->addOne("VSgamesStarted"); -} - -//Starts new Vs Game (two Player) -void BlockGame::NewVsGame(BlockGame* target, bool AI, unsigned int ticks) { - NewGame(ticks); - vsMode = true; - AI_Enabled = AI; - if (!AI) { - Stats::getInstance()->addOne("VSgamesStarted"); - } - else { - name = "CPU"; - } - putStartBlocks(); - garbageTarget = target; -} //Prints "winner" and ends game void BlockGame::setPlayerWon() { @@ -1921,6 +1909,14 @@ int BlockGame::getLevel() const { return Level; } +void BlockGame::setGarbageTarget(BlockGame* garbageTarget) { + this->garbageTarget = garbageTarget; +} + +BlockGame* BlockGame::getGarbageTarget() const { + return garbageTarget; +} + //Play the next level void nextLevel(BlockGame& g, unsigned int ticks) { BlockGameStartInfo s; diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index 3596f56..2deeb7d 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp @@ -67,6 +67,14 @@ struct BlockGameStartInfo { ///True if puzzle mode. level must be set too. bool puzzleMode = false; int level = 0; + bool AI = false; + bool vsMode = false; +}; + +struct GarbageStruct { + bool greyGarbage = false; + int width = 6; + int height = 1; }; //////////////////////////////////////////////////////////////////////////////// @@ -185,10 +193,6 @@ public: void MoveCursorTo(int x, int y); bool GetIsWinner() const; void NewGame(const BlockGameStartInfo &s); - //Starts new Vs Game (two Player) - void NewVsGame(BlockGame *target,unsigned int ticks); - //Starts new Vs Game (two Player) - void NewVsGame(BlockGame *target, bool AI,unsigned int ticks); void putStartBlocks(int n); //Creates garbage using a given wide and height bool CreateGarbage(int wide, int height); @@ -222,6 +226,8 @@ public: void setSinglePuzzle(bool singlePuzzle); bool isSinglePuzzle() const; int getLevel() const; + void setGarbageTarget(BlockGame* garbageTarget); + BlockGame* getGarbageTarget() const; private: void NewGame(unsigned int ticks); //Test if LineNr is an empty line, returns false otherwise. diff --git a/source/code/main.cpp b/source/code/main.cpp index a082a7c..148ad4a 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -1551,8 +1551,13 @@ static void StarTwoPlayerTimeTrial() { static void StartTwoPlayerVs() { //2 player - VsMode - player1->NewVsGame(player2,SDL_GetTicks()); - player2->NewVsGame(player1,SDL_GetTicks()); + BlockGameStartInfo startInfo; + startInfo.ticks = SDL_GetTicks(); + startInfo.vsMode = true; + player1->NewGame(startInfo); + player1->setGarbageTarget(player2); + player2->NewGame(startInfo); + player2->setGarbageTarget(player1); //vsMode = true; twoPlayers = true; player1->setGameSpeed(player1Speed); @@ -1978,8 +1983,13 @@ int runGame(int gametype, int level) { case 4: { //1 player - Vs mode int theAIlevel = level; //startSingleVs(); - theGame.NewVsGame(&theGame2, SDL_GetTicks()); - theGame2.NewVsGame(&theGame, SDL_GetTicks()); + BlockGameStartInfo startInfo; + startInfo.ticks = SDL_GetTicks(); + startInfo.vsMode = true; + theGame.NewGame(startInfo); + theGame.setGarbageTarget(&theGame2); + theGame2.NewGame(startInfo); + theGame2.setGarbageTarget(&theGame); DrawIMG(backgroundImage, screen, 0, 0); twoPlayers = true; //Single player, but AI plays theGame2.setAIlevel((Uint8)theAIlevel);