Skip to content

Commit c60f3de

Browse files
committed
Changed it to a single state instead of a state stack
1 parent d30abd7 commit c60f3de

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

include/GameController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GameController {
2525
GameBoard& model;
2626
GameView& view;
2727

28-
std::vector<ControlState> stateStack;
28+
ControlState state;
2929
std::vector<Coordinate> clickHistory;
3030

3131
GameController(const GameController& o) : model(o.model), view(o.view) {} //deleted

src/GameController.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
121121
std::bind(&GameController::handleBoardEvent, this, _1),
122122
getGraphicsConfig()["screen.board.area"]));
123123

124-
stateStack.push_back(BASESTATE);
124+
state = BASESTATE;
125125
}
126126

127127
/**
@@ -135,28 +135,26 @@ GameController::~GameController() {
135135
* Pushes the given state onto the control stack
136136
*/
137137
void GameController::pushState(ControlState newState){
138-
if (newState != BASESTATE){
139-
stateStack.push_back(newState);
138+
if(state != BASESTATE) {
139+
throw std::runtime_error("oh no! i misunderstood how this function works");
140140
}
141+
state = newState;
141142
}
142143

143144
/**
144145
* Pops the latest state from the control stack
145146
*/
146147
ControlState GameController::popState(){
147148
ControlState currState = getState();
148-
if(currState == BASESTATE){
149-
return currState;
150-
}
151-
stateStack.pop_back();
149+
state = BASESTATE;
152150
return currState;
153151
}
154152

155153
/**
156154
* returns the current state of the controller
157155
*/
158156
ControlState GameController::getState(){
159-
return stateStack.back();
157+
return state;
160158
}
161159

162160
/**
@@ -259,14 +257,15 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
259257

260258
break;
261259
case BUILDROAD_DEVCARD:
262-
storeClick(coord);
260+
if(getClickHistorySize() <= 4) {
261+
storeClick(coord);
262+
}
263263
if(getClickHistorySize() >= 4){
264264
using namespace std::placeholders;
265265
view.addElement(28, makeConfirmationDialogue(
266266
std::bind(&GameController::handleConfirmRoadCard, this, _1),
267267
std::bind(&GameController::handleCancelDialogueEvent, this, _1), {{.2, .3}, {.8, .6}},
268268
"Use road building card on these points?"));
269-
pushState(MODALSTATE);
270269
}
271270
break;
272271
case KNIGHT_DEVCARD:

0 commit comments

Comments
 (0)