Skip to content

Commit c1368c9

Browse files
committed
Upgrade to Wonder button and action
1 parent 7dd129b commit c1368c9

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

include/GameBoard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ class GameBoard {
120120
bool canUpgradeSettlement(Coordinate location, const Player& owner) const;
121121
bool buyUpgradeOnSettlement(Coordinate location, Player& owner);
122122

123+
bool canUpgradeToWonder(Coordinate location, const Player& owner) const;
124+
bool buyUpgradeOnWonder(Coordinate location, Player& owner);
125+
123126
//void PlaceSettlement(Coordinate location, Player& Owner);
124127
void PlaceCity(Coordinate location, Player& Owner);
125128
void PlaceWonder(Coordinate location, Player& Owner);

include/GameController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class GameView;
1212
class Player;
1313

1414

15-
enum ControlState {BASESTATE, MODALSTATE, BUILDROAD, BUILDSETTLEMENT, BUILDCITY, ROBBER,
15+
enum ControlState {BASESTATE, MODALSTATE, BUILDROAD, BUILDSETTLEMENT, BUILDCITY, BUILDWONDER, ROBBER,
1616
VICTORYPOINT_DEVCARD, BUILDROAD_DEVCARD, KNIGHT_DEVCARD, YEAROFPLENTY_DEVCARD, MONOPOLY_DEVCARD};
1717

1818

@@ -39,6 +39,7 @@ class GameController {
3939
bool handleRoadButtonEvent(ScreenCoordinate);
4040
bool handleSettlementButtonEvent(ScreenCoordinate);
4141
bool handleCityButtonEvent(ScreenCoordinate);
42+
bool handleWonderButtonEvent(ScreenCoordinate);
4243
bool handleRoadCardButtonEvent(ScreenCoordinate);
4344

4445
bool handleBuyDevelopmentCardButtonEvent(ScreenCoordinate);

src/GameBoard.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,43 @@ bool GameBoard::buyUpgradeOnSettlement(Coordinate location, Player& owner) {
865865
return false;
866866
}
867867

868+
/**
869+
* Whether a settlement/city at a location can be upgraded to a wonder.
870+
*/
871+
bool GameBoard::canUpgradeToWonder(Coordinate location, const Player& owner) const {
872+
auto it = corners.find(location);
873+
if(it == corners.end()) {
874+
std::cout << "there's nothing there" << std::endl;
875+
return false;
876+
}
877+
if(!it->second) {
878+
std::cout << "null ptr there" << std::endl;
879+
return false;
880+
}
881+
if(!(it->second->getOwner() == owner)) {
882+
std::cout << "wrong owner" << std::endl;
883+
return false;
884+
}
885+
if(dynamic_cast<const Settlement*>(it->second.get()) == 0 && dynamic_cast<const City*>(it->second.get()) == 0) {
886+
std::cout << "this isn't a settlement or city" << std::endl;
887+
return false;
888+
}
889+
return true;
890+
}
891+
892+
bool GameBoard::buyUpgradeOnWonder(Coordinate location, Player& owner) {
893+
if(canUpgradeToWonder(location, owner) && owner.canBuyCity()) {
894+
if(!owner.buyWonder()) {
895+
std::cout << "wat" << std::endl;
896+
return false;
897+
}
898+
UpgradeToWonder(location);
899+
return true;
900+
}
901+
std::cout << "failed for some reason" << std::endl;
902+
return false;
903+
}
904+
868905
/**
869906
* Place a city on the board.
870907
* @param location Where to place it on the board.

src/GameController.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
2525

2626
view.addElement(makeViewButtonText(std::bind(&GameController::handleRoadButtonEvent, this, _1), {{0, 0}, {0.1, 0.10}}, font, fontSize, "Road |"));
2727
view.addElement(makeViewButtonText(std::bind(&GameController::handleCityButtonEvent, this, _1), {{0.10, 0.0}, {0.20, 0.1}}, font, fontSize, "City |"));
28-
view.addElement(makeViewButtonText(std::bind(&GameController::handleSettlementButtonEvent, this, _1), {{0.20, 0.0}, {0.33, 0.1}}, font, fontSize, "Settlement"));
28+
view.addElement(makeViewButtonText(std::bind(&GameController::handleSettlementButtonEvent, this, _1), {{0.20, 0.0}, {0.33, 0.1}}, font, fontSize, "Settlement |"));
29+
view.addElement(makeViewButtonText(std::bind(&GameController::handleWonderButtonEvent, this, _1), {{0.33, 0.0}, {0.43, 0.1}}, font, fontSize, "Wonder"));
2930
view.addElement(makeViewButtonText(std::bind(&GameController::nextTurn, this, _1), {{0, 0.3}, {0.1, 0.4}}, font, fontSize, "End Turn"));
3031

3132
auto playerTopY = 0.9;
@@ -227,6 +228,11 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
227228
model.buyUpgradeOnSettlement(coord, model.getCurrentPlayer());
228229
handleCancelButtonEvent(screenCoord);
229230
break;
231+
case BUILDWONDER:
232+
std::cout << "attempting to build a wonder" << std::endl;
233+
model.buyUpgradeOnWonder(coord, model.getCurrentPlayer());
234+
handleCancelButtonEvent(screenCoord);
235+
break;
230236
default:
231237
break;
232238
}
@@ -316,6 +322,21 @@ bool GameController::handleCityButtonEvent(ScreenCoordinate coord) {
316322
return true;
317323
}
318324

325+
/**
326+
* Handles a click on the "create city" button. Changes the internal state to indicate the user is going to be upgrading settlements to cities on the board.
327+
* @param coord The place the user clicked on screen.
328+
* @return Whether this event was handled by this element. Always true.
329+
*/
330+
bool GameController::handleCityButtonEvent(ScreenCoordinate coord) {
331+
if(getState() != BASESTATE) {
332+
return false;
333+
}
334+
335+
view.setControlStateText("Click on a settlement/city to upgrade to wonder. (5 of ea rsc)");
336+
pushState(BUILDWONDER);
337+
return true;
338+
}
339+
319340

320341
/**
321342
* Handles a click on the road Building Card button. This changes the control state to indicate the user is going to be building roads on the board.

0 commit comments

Comments
 (0)