commit 167c2a1d
Made the mouse play private in the BlockGame class
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 010afcd..5db2cc9 100644
--- a/source/code/BlockGame.cpp
+++ b/source/code/BlockGame.cpp
@@ -1818,6 +1818,15 @@ void BlockGame::DoAction (const BlockGameAction& action) {
}
}
}
+ if (action.action == BlockGameAction::Action::MOUSE_DOWN) {
+ MouseDown(action.x, action.y);
+ }
+ if (action.action == BlockGameAction::Action::MOUSE_UP) {
+ MouseUp();
+ }
+ if (action.action == BlockGameAction::Action::MOUSE_MOVE) {
+ MouseMove(action.x);
+ }
}
bool BlockGame::isSinglePuzzle() const {
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp
index c81f928..01c971e 100644
--- a/source/code/BlockGame.hpp
+++ b/source/code/BlockGame.hpp
@@ -79,10 +79,12 @@ struct GarbageStruct {
};
struct BlockGameAction {
- enum class Action {NONE, UPDATE, SET_DRAW, SET_WON, SET_GAME_OVER, MOVE, SWITCH, PUSH, PUSH_GARBAGE};
+ enum class Action {NONE, UPDATE, SET_DRAW, SET_WON, SET_GAME_OVER, MOVE, SWITCH, PUSH, PUSH_GARBAGE, MOUSE_DOWN, MOUSE_UP, MOUSE_MOVE};
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'
+ int x = 0;
+ int y = 0;
std::vector<GarbageStruct> garbage;
};
@@ -211,9 +213,6 @@ public:
int GetCursorY() const;
void MoveCursorTo(int x, int y);
void GetMouseCursor(bool& pressed, int& x, int&y) const;
- void MouseDown(int x, int y); //Send then the mouse is pressed
- void MouseMove(int x); //Send then the mouse moves
- void MouseUp(); //Send then the mouse goes up
bool GetIsWinner() const;
bool isSinglePuzzle() const;
int getLevel() const;
@@ -262,6 +261,9 @@ private:
bool CreateGarbage(int wide, int height);
//Creates garbage using a given wide and height
bool CreateGreyGarbage();
+ void MouseDown(int x, int y); //Send then the mouse is pressed
+ void MouseMove(int x); //Send then the mouse moves
+ void MouseUp(); //Send then the mouse goes up
///////////////////////////////////////////////////////////////////////////
/////////////////////////// AI starts here! ///////////////////////////////
///////////////////////////////////////////////////////////////////////////
diff --git a/source/code/main.cpp b/source/code/main.cpp
index d0bd598..34f94a7 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -1799,11 +1799,17 @@ int runGame(int gametype, int level) {
int y = 0;
theGame.GetBrickCoordinateFromMouse(pressed, event.button.x, event.button.y, x, y);
if (pressed) {
- theGame.MouseDown(x, y);
+ a.action = BlockGameAction::Action::MOUSE_DOWN;
+ a.x = x;
+ a.y = y;
+ theGame.DoAction(a);
}
theGame2.GetBrickCoordinateFromMouse(pressed, event.button.x, event.button.y, x, y);
if (pressed) {
- theGame2.MouseDown(x, y);
+ a.action = BlockGameAction::Action::MOUSE_DOWN;
+ a.x = x;
+ a.y = y;
+ theGame2.DoAction(a);
}
mouseDownX = event.button.x;
mouseDownY = event.button.y;
@@ -1828,8 +1834,9 @@ int runGame(int gametype, int level) {
if (event.button.button == SDL_BUTTON_LEFT) {
int x = event.button.x;
int y = event.button.y;
- theGame.MouseUp();
- theGame2.MouseUp();
+ a.action = BlockGameAction::Action::MOUSE_UP;
+ theGame.DoAction(a);
+ theGame2.DoAction(a);
if (theGame.IsInTheBoard(x,y) && theGame.IsUnderTheBoard(mouseDownX, mouseDownY)) {
a.action = BlockGameAction::Action::PUSH;
theGame.DoAction(a);
@@ -1852,7 +1859,9 @@ int runGame(int gametype, int level) {
theGame.GetBrickCoordinateFromMouse(pressed, event.motion.x, event.motion.y, mx, my);
if (pressed) {
if (mx != x) {
- theGame.MouseMove(mx);
+ a.action = BlockGameAction::Action::MOUSE_MOVE;
+ a.x = mx;
+ theGame.DoAction(a);
}
}
}
@@ -1863,7 +1872,9 @@ int runGame(int gametype, int level) {
theGame2.GetBrickCoordinateFromMouse(pressed, event.motion.x, event.motion.y, mx, my);
if (pressed) {
if (mx != x) {
- theGame2.MouseMove(mx);
+ a.action = BlockGameAction::Action::MOUSE_MOVE;
+ a.x = mx;
+ theGame2.DoAction(a);
}
}
}