git repos / blockattack-game

commit 62b3f619

sago007 · 2016-05-20 07:01
62b3f619ff042d5b9bd982542288df764c73b3b5 patch · browse files
parent 07f5b3f379543e7e794a3ecfca494789177fd9fc

Changed the action to a enum

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 98659a6..690638d 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp
@@ -1786,13 +1786,13 @@ void BlockGame::UpdateInternal(unsigned int newtick) {
}
void BlockGame::DoAction (const BlockGameAction& action) {
- if (action.isUpdate) {
+ if (action.action == BlockGameAction::Action::UPDATE) {
UpdateInternal(action.tick);
}
- if (action.setDraw) {
+ if (action.action == BlockGameAction::Action::SET_DRAW) {
setDraw();
}
- if (action.setPlayerWon) {
+ if (action.action == BlockGameAction::Action::SET_WON) {
setPlayerWon();
}
}
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index cb652bd..df9d4ed 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp
@@ -79,10 +79,9 @@ struct GarbageStruct {
};
struct BlockGameAction {
+ enum class Action {NONE, UPDATE, SET_DRAW, SET_WON};
+ Action action = Action::NONE;
unsigned int tick = 0;
- bool isUpdate = false;
- bool setDraw = false;
- bool setPlayerWon = false;
};
////////////////////////////////////////////////////////////////////////////////
diff --git a/source/code/main.cpp b/source/code/main.cpp index 7fac99e..f252ff3 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -1884,7 +1884,7 @@ int runGame(int gametype, int level) {
bNearDeath = theGame.IsNearDeath() || theGame2.IsNearDeath();
//Updates the objects
BlockGameAction a;
- a.isUpdate = true;
+ a.action = BlockGameAction::Action::UPDATE;
a.tick = SDL_GetTicks();
theGame.DoAction(a);
theGame2.DoAction(a);
@@ -1897,17 +1897,17 @@ int runGame(int gametype, int level) {
if ((theGame.isGameOver()) && (theGame2.isGameOver())) {
if (theGame.GetScore()+theGame.GetHandicap()>theGame2.GetScore()+theGame2.GetHandicap()) {
BlockGameAction a;
- a.setPlayerWon = true;
+ a.action = BlockGameAction::Action::SET_WON;
theGame.DoAction(a);
}
else if (theGame.GetScore()+theGame.GetHandicap()<theGame2.GetScore()+theGame2.GetHandicap()) {
BlockGameAction a;
- a.setPlayerWon = true;
+ a.action = BlockGameAction::Action::SET_WON;
theGame2.DoAction(a);
}
else {
BlockGameAction a;
- a.setDraw = true;
+ a.action = BlockGameAction::Action::SET_DRAW;
theGame.DoAction(a);
theGame2.DoAction(a);
}
@@ -1915,12 +1915,12 @@ int runGame(int gametype, int level) {
}
if ((theGame.isGameOver()) && (!theGame2.isGameOver())) {
BlockGameAction a;
- a.setPlayerWon = true;
+ a.action = BlockGameAction::Action::SET_WON;
theGame2.DoAction(a);
}
if ((!theGame.isGameOver()) && (theGame2.isGameOver())) {
BlockGameAction a;
- a.setPlayerWon = true;
+ a.action = BlockGameAction::Action::SET_WON;
theGame.DoAction(a);
}
vector<GarbageStruct> gs;