Skip to content

Commit 884c257

Browse files
committed
Merge pull request #60 from Databean/cp_UI2
Upgrade to Wonder button and action
2 parents 84294ee + 18765fd commit 884c257

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
@@ -873,6 +873,43 @@ bool GameBoard::buyUpgradeOnSettlement(Coordinate location, Player& owner) {
873873
return false;
874874
}
875875

876+
/**
877+
* Whether a settlement/city at a location can be upgraded to a wonder.
878+
*/
879+
bool GameBoard::canUpgradeToWonder(Coordinate location, const Player& owner) const {
880+
auto it = corners.find(location);
881+
if(it == corners.end()) {
882+
std::cout << "there's nothing there" << std::endl;
883+
return false;
884+
}
885+
if(!it->second) {
886+
std::cout << "null ptr there" << std::endl;
887+
return false;
888+
}
889+
if(!(it->second->getOwner() == owner)) {
890+
std::cout << "wrong owner" << std::endl;
891+
return false;
892+
}
893+
if(dynamic_cast<const Settlement*>(it->second.get()) == 0 && dynamic_cast<const City*>(it->second.get()) == 0) {
894+
std::cout << "this isn't a settlement or city" << std::endl;
895+
return false;
896+
}
897+
return true;
898+
}
899+
900+
bool GameBoard::buyUpgradeOnWonder(Coordinate location, Player& owner) {
901+
if(canUpgradeToWonder(location, owner) && owner.canBuyCity()) {
902+
if(!owner.buyWonder()) {
903+
std::cout << "wat" << std::endl;
904+
return false;
905+
}
906+
UpgradeToWonder(location);
907+
return true;
908+
}
909+
std::cout << "failed for some reason" << std::endl;
910+
return false;
911+
}
912+
876913
/**
877914
* Place a city on the board.
878915
* @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.82;
@@ -223,6 +224,11 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
223224
model.buyUpgradeOnSettlement(coord, model.getCurrentPlayer());
224225
handleCancelButtonEvent(screenCoord);
225226
break;
227+
case BUILDWONDER:
228+
std::cout << "attempting to build a wonder" << std::endl;
229+
model.buyUpgradeOnWonder(coord, model.getCurrentPlayer());
230+
handleCancelButtonEvent(screenCoord);
231+
break;
226232
default:
227233
break;
228234
}
@@ -312,6 +318,21 @@ bool GameController::handleCityButtonEvent(ScreenCoordinate coord) {
312318
return true;
313319
}
314320

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

316337
/**
317338
* 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)