diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index 690638d..e5a4586 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp @@ -1795,6 +1795,9 @@ void BlockGame::DoAction (const BlockGameAction& action) { if (action.action == BlockGameAction::Action::SET_WON) { setPlayerWon(); } + if (action.action == BlockGameAction::Action::PUSH) { + PushLine(); + } } bool BlockGame::isSinglePuzzle() const { diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index df9d4ed..681b0d5 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp @@ -79,7 +79,7 @@ struct GarbageStruct { }; struct BlockGameAction { - enum class Action {NONE, UPDATE, SET_DRAW, SET_WON}; + enum class Action {NONE, UPDATE, SET_DRAW, SET_WON, PUSH}; Action action = Action::NONE; unsigned int tick = 0; }; @@ -221,8 +221,6 @@ public: void MoveCursor(char way); //switches the two blocks at the cursor position, unless game over void SwitchAtCursor(); - //Generates a new line and moves the field one block up (restart puzzle mode) - void PushLine(); private: void NewGame(unsigned int ticks); //Test if LineNr is an empty line, returns false otherwise. @@ -254,6 +252,8 @@ private: void PushPixels(); //See how high the tower is, saved in integer TowerHeight void FindTowerHeight(); + //Generates a new line and moves the field one block up (restart puzzle mode) + void PushLine(); /////////////////////////////////////////////////////////////////////////// /////////////////////////// AI starts here! /////////////////////////////// /////////////////////////////////////////////////////////////////////////// diff --git a/source/code/main.cpp b/source/code/main.cpp index f252ff3..e803f28 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -1604,6 +1604,10 @@ int runGame(int gametype, int level) { bool mustWriteScreenshot = false; + BlockGameAction a; + a.action = BlockGameAction::Action::NONE; + a.tick = SDL_GetTicks(); + if (true) { SDL_Event event; @@ -1638,7 +1642,8 @@ int runGame(int gametype, int level) { theGame.MoveCursor('E'); } if ( event.key.keysym.sym == keySettings[player1keys].push ) { - theGame.PushLine(); + a.action = BlockGameAction::Action::PUSH; + theGame.DoAction(a); } if ( event.key.keysym.sym == keySettings[player1keys].change ) { theGame.SwitchAtCursor(); @@ -1659,7 +1664,8 @@ int runGame(int gametype, int level) { theGame2.MoveCursor('E'); } if ( event.key.keysym.sym == keySettings[player2keys].push ) { - theGame2.PushLine(); + a.action = BlockGameAction::Action::PUSH; + theGame2.DoAction(a); } if ( event.key.keysym.sym == keySettings[player2keys].change ) { theGame2.SwitchAtCursor(); @@ -1710,7 +1716,8 @@ int runGame(int gametype, int level) { theGame.SwitchAtCursor(); } if (isPlayerPushEvent(1, event)) { - theGame.PushLine(); + a.action = BlockGameAction::Action::PUSH; + theGame.DoAction(a); } if (isPlayerUpEvent(2, event)) { theGame2.MoveCursor('N'); @@ -1728,7 +1735,8 @@ int runGame(int gametype, int level) { theGame2.SwitchAtCursor(); } if (isPlayerPushEvent(2, event)) { - theGame2.PushLine(); + a.action = BlockGameAction::Action::PUSH; + theGame2.DoAction(a); } static int mouseDownX = 0; static int mouseDownY = 0; @@ -1754,11 +1762,13 @@ int runGame(int gametype, int level) { int y = 0; theGame.GetBrickCoordinateFromMouse(pressed, event.button.x, event.button.y, x, y); if (pressed) { - theGame.PushLine(); + a.action = BlockGameAction::Action::PUSH; + theGame.DoAction(a); } theGame2.GetBrickCoordinateFromMouse(pressed, event.button.x, event.button.y, x, y); if (pressed) { - theGame2.PushLine(); + a.action = BlockGameAction::Action::PUSH; + theGame2.DoAction(a); } } } @@ -1769,10 +1779,12 @@ int runGame(int gametype, int level) { theGame.MouseUp(); theGame2.MouseUp(); if (theGame.IsInTheBoard(x,y) && theGame.IsUnderTheBoard(mouseDownX, mouseDownY)) { - theGame.PushLine(); + a.action = BlockGameAction::Action::PUSH; + theGame.DoAction(a); } if (theGame2.IsInTheBoard(x,y) && theGame2.IsUnderTheBoard(mouseDownX, mouseDownY)) { - theGame2.PushLine(); + a.action = BlockGameAction::Action::PUSH; + theGame2.DoAction(a); } } } @@ -1883,9 +1895,7 @@ int runGame(int gametype, int level) { //set bNearDeath to false theGame*.Update() will change to true as needed bNearDeath = theGame.IsNearDeath() || theGame2.IsNearDeath(); //Updates the objects - BlockGameAction a; a.action = BlockGameAction::Action::UPDATE; - a.tick = SDL_GetTicks(); theGame.DoAction(a); theGame2.DoAction(a);