git repos / blockattack-game

commit 8d5e5953

sago007 · 2016-06-04 13:15
8d5e59537208b07bb6f5af71eeb24ebdf18b0936 patch · browse files
parent e5a239128edf4fcef79463ca74d1d7b39e5cc49c

Moved the create garbage into DoAction. Changed the version number.

Changed files

M source/code/BlockGame.cpp before
M source/code/BlockGame.hpp before
M source/code/main.cpp before
M source/code/version.h before
diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index 24c097f..010afcd 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp
@@ -1808,6 +1808,16 @@ void BlockGame::DoAction (const BlockGameAction& action) {
if (action.action == BlockGameAction::Action::SWITCH) {
SwitchAtCursor();
}
+ if (action.action == BlockGameAction::Action::PUSH_GARBAGE) {
+ for (const GarbageStruct& i : action.garbage) {
+ if (i.greyGarbage) {
+ CreateGreyGarbage();
+ }
+ else {
+ CreateGarbage(i.width, i.height);
+ }
+ }
+ }
}
bool BlockGame::isSinglePuzzle() const {
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index 16bf2ce..c81f928 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp
@@ -79,10 +79,11 @@ struct GarbageStruct {
};
struct BlockGameAction {
- enum class Action {NONE, UPDATE, SET_DRAW, SET_WON, SET_GAME_OVER, MOVE, SWITCH, PUSH};
+ enum class Action {NONE, UPDATE, SET_DRAW, SET_WON, SET_GAME_OVER, MOVE, SWITCH, PUSH, PUSH_GARBAGE};
Action action = Action::NONE;
unsigned int tick = 0; //< Used for update
char way = '\0'; //< The direction to move the cursor: 'N', 'E', 'S' or 'W'
+ std::vector<GarbageStruct> garbage;
};
////////////////////////////////////////////////////////////////////////////////
@@ -183,6 +184,13 @@ public:
void NewGame(const BlockGameStartInfo &s);
void DoAction (const BlockGameAction& action);
+ /**
+ * This function returns all the garbage.
+ * This is actual const in the way that it does not change the games state
+ * Technically it is not const because it empties the queue that are stored inside the object even if not part of the game state.
+ * @param poppedData
+ */
+ void PopSendGarbage(std::vector<GarbageStruct>& poppedData);
int GetScore() const;
int GetHandicap() const;
@@ -211,11 +219,6 @@ public:
int getLevel() const;
bool GetAIenabled() const;
bool IsNearDeath() const;
- //Creates garbage using a given wide and height
- bool CreateGarbage(int wide, int height);
- //Creates garbage using a given wide and height
- bool CreateGreyGarbage();
- void PopSendGarbage(std::vector<GarbageStruct>& poppedData);
private:
void NewGame(unsigned int ticks);
//Test if LineNr is an empty line, returns false otherwise.
@@ -255,6 +258,10 @@ private:
void MoveCursor(char way);
//switches the two blocks at the cursor position, unless game over
void SwitchAtCursor();
+ //Creates garbage using a given wide and height
+ bool CreateGarbage(int wide, int height);
+ //Creates garbage using a given wide and height
+ bool CreateGreyGarbage();
///////////////////////////////////////////////////////////////////////////
/////////////////////////// AI starts here! ///////////////////////////////
///////////////////////////////////////////////////////////////////////////
diff --git a/source/code/main.cpp b/source/code/main.cpp index 4412f77..d0bd598 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -1988,22 +1988,18 @@ int runGame(int gametype, int level) {
vector<GarbageStruct> gs;
theGame.PopSendGarbage(gs);
for (const GarbageStruct& g : gs ) {
- if (g.greyGarbage) {
- theGame2.CreateGreyGarbage();
- }
- else {
- theGame2.CreateGarbage(g.width, g.height);
- }
+ BlockGameAction a;
+ a.action = BlockGameAction::Action::PUSH_GARBAGE;
+ a.garbage.push_back(g);
+ theGame2.DoAction(a);
}
gs.clear();
theGame2.PopSendGarbage(gs);
for (const GarbageStruct& g : gs ) {
- if (g.greyGarbage) {
- theGame.CreateGreyGarbage();
- }
- else {
- theGame.CreateGarbage(g.width, g.height);
- }
+ BlockGameAction a;
+ a.action = BlockGameAction::Action::PUSH_GARBAGE;
+ a.garbage.push_back(g);
+ theGame.DoAction(a);
}
}
diff --git a/source/code/version.h b/source/code/version.h index e2341fb..e51d93d 100644 --- a/source/code/version.h +++ b/source/code/version.h
@@ -22,5 +22,5 @@ http://www.blockattack.net
*/
#ifndef VERSION_NUMBER
-#define VERSION_NUMBER "2.0.0-SNAPSHOT"
+#define VERSION_NUMBER "2.1.0-SNAPSHOT"
#endif
\ No newline at end of file