git repos / blockattack-game

commit 07f5b3f3

sago007 · 2016-05-19 19:37
07f5b3f379543e7e794a3ecfca494789177fd9fc patch · browse files
parent de82a6c89f4eb65d42332e07a76bc483a000db3a

More actions through the DoAction method

Changed files

M source/code/BlockGame.cpp before
M source/code/BlockGame.hpp before
M source/code/main.cpp before
diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index af80ef7..98659a6 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp
@@ -1789,6 +1789,12 @@ void BlockGame::DoAction (const BlockGameAction& action) {
if (action.isUpdate) {
UpdateInternal(action.tick);
}
+ if (action.setDraw) {
+ setDraw();
+ }
+ if (action.setPlayerWon) {
+ setPlayerWon();
+ }
}
bool BlockGame::isSinglePuzzle() const {
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index 733f9d2..cb652bd 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp
@@ -81,7 +81,8 @@ struct GarbageStruct {
struct BlockGameAction {
unsigned int tick = 0;
bool isUpdate = false;
-
+ bool setDraw = false;
+ bool setPlayerWon = false;
};
////////////////////////////////////////////////////////////////////////////////
@@ -223,10 +224,6 @@ public:
void SwitchAtCursor();
//Generates a new line and moves the field one block up (restart puzzle mode)
void PushLine();
- //Prints "winner" and ends game
- void setPlayerWon();
- //Prints "draw" and ends the game
- void setDraw();
private:
void NewGame(unsigned int ticks);
//Test if LineNr is an empty line, returns false otherwise.
@@ -296,6 +293,10 @@ private:
//Set the move speed of the AI based on the aiLevel parameter
void setAIlevel(int aiLevel);
void PushLineInternal();
+ //Prints "winner" and ends game
+ void setPlayerWon();
+ //Prints "draw" and ends the game
+ void setDraw();
//Updates evrything, if not called nothing happends
void Update();
void UpdateInternal(unsigned int newtick);
diff --git a/source/code/main.cpp b/source/code/main.cpp index bd33321..7fac99e 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -1896,24 +1896,32 @@ int runGame(int gametype, int level) {
if (twoPlayers) {
if ((theGame.isGameOver()) && (theGame2.isGameOver())) {
if (theGame.GetScore()+theGame.GetHandicap()>theGame2.GetScore()+theGame2.GetHandicap()) {
- theGame.setPlayerWon();
+ BlockGameAction a;
+ a.setPlayerWon = true;
+ theGame.DoAction(a);
}
else if (theGame.GetScore()+theGame.GetHandicap()<theGame2.GetScore()+theGame2.GetHandicap()) {
- theGame2.setPlayerWon();
+ BlockGameAction a;
+ a.setPlayerWon = true;
+ theGame2.DoAction(a);
}
else {
- theGame.setDraw();
- theGame2.setDraw();
+ BlockGameAction a;
+ a.setDraw = true;
+ theGame.DoAction(a);
+ theGame2.DoAction(a);
}
//twoPlayers = false;
}
if ((theGame.isGameOver()) && (!theGame2.isGameOver())) {
- theGame2.setPlayerWon();
- //twoPlayers = false;
+ BlockGameAction a;
+ a.setPlayerWon = true;
+ theGame2.DoAction(a);
}
if ((!theGame.isGameOver()) && (theGame2.isGameOver())) {
- theGame.setPlayerWon();
- //twoPlayers = false;
+ BlockGameAction a;
+ a.setPlayerWon = true;
+ theGame.DoAction(a);
}
vector<GarbageStruct> gs;
theGame.PopSendGarbage(gs);