Skip to content

Commit 191c074

Browse files
committed
Added resource& dev card show/hide functionality, but can't get the button to draw properly.
1 parent c4c397f commit 191c074

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

include/GameController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class GameController {
5757

5858
bool handleConfirmRoadCard(ScreenCoordinate);
5959
bool handleCancelDialogueEvent(ScreenCoordinate);
60+
61+
bool viewCardTotals(ScreenCoordinate coord);
6062

6163
void pushState(ControlState);
6264
ControlState getState();

include/GameView.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ class GameView {
5252
std::vector<ScreenCoordinate> pointsOfInterest;
5353

5454
void highlightPoint(ScreenCoordinate & coord);
55-
void drawCardCount(std::string font, int fontSize);
56-
void drawResourceCount(std::string font, int fontSize);
5755

5856
std::string controlStateText;
5957

6058
GameView(const GameView& o) = delete;
6159
GameView& operator=(const GameView& o) = delete;
60+
6261
public:
6362
GameView(GameBoard&);
6463
~GameView();
@@ -78,6 +77,10 @@ class GameView {
7877
std::unique_ptr<ViewElement> removeElement(int priority);
7978
std::unique_ptr<ViewElement> removeElement(const ViewElement*);
8079
std::unique_ptr<ViewElement> removeElement(const ViewElement&);
80+
81+
void drawCardCount(std::string font, int fontSize);
82+
void drawResourceCount(std::string font, int fontSize);
83+
bool showTotals;
8184
};
8285

8386
/**

src/GameController.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
3838

3939
view.addElement(makeViewButtonText(std::bind(&GameController::handleCancelButtonEvent, this, _1), {{.92, .96}, {1.0, 1.0}}, font, fontSize, "Cancel"));
4040

41-
view.addElement(makeViewButtonText(std::bind(&GameController::handleBuyDevelopmentCardButtonEvent, this, _1), {{.85, .23}, {1, .30}}, font, fontSize, "Development Cards"));
41+
view.addElement(makeViewButtonText(std::bind(/*&GameController::handleBuyDevelopmentCardButtonEvent*/&GameController::viewCardTotals, this, _1), {{.85, .23}, {1, .30}}, font, fontSize, "Development Cards"));
4242
view.addElement(makeViewButtonText(std::bind(&GameController::handleRoadCardButtonEvent, this, _1), {{0.85, 0.0}, {0.97, 0.05}}, font, fontSize, "Road Building "));
4343
view.addElement(makeViewButtonText(std::bind(&GameController::handleKnightCardButtonEvent, this, _1), {{0.85, 0.05}, {0.97, 0.10}}, font, fontSize, "Knight "));
4444
view.addElement(makeViewButtonText(std::bind(&GameController::handleYearOfPlentyCardButtonEvent, this, _1), {{0.85, 0.10}, {0.97, 0.15}}, font, fontSize, "Year of Plenty "));
@@ -50,6 +50,8 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
5050
view.addElement(makeViewButtonText(std::bind(&GameController::handleOreButtonEvent, this, _1), {{.85, .45}, {.97, .50}}, font, fontSize, "Ore "));
5151
view.addElement(makeViewButtonText(std::bind(&GameController::handleBrickButtonEvent, this, _1), {{.85, .50}, {.97, .55}}, font, fontSize, "Brick "));
5252
view.addElement(makeViewButtonText(std::bind(&GameController::handleWheatButtonEvent, this, _1), {{.85, .55}, {.97, .60}}, font, fontSize, "Wheat "));
53+
54+
//view.addElement(makeViewButtonText(std::bind(&GameController::viewCardTotals, this, _1), {{.85, .35}, {.97, .35}}, font, fontSize, "Show Totals"));
5355

5456

5557
stateStack.push_back(BASESTATE);
@@ -145,13 +147,15 @@ void printPlayerInfo(const Player& player) {
145147
}
146148

147149
/**
148-
* calls a function to advance turn, check for victory and roll dice
150+
* calls a function to advance turn, hide resource and development cards, check for victory, and roll dice
149151
*/
150152
bool GameController::nextTurn(ScreenCoordinate) {
151153
if(getState() != BASESTATE){
152154
return false;
153155
}
154-
156+
157+
view.showTotals = false;
158+
155159
model.endTurn();
156160
if (model.getDice().getFirst() + model.getDice().getSecond() == 7)
157161
{
@@ -413,6 +417,19 @@ bool GameController::handleVictoryPointCardButtonEvent(ScreenCoordinate coord){
413417
return true;
414418
}
415419

420+
/**
421+
* Makes the development and resource card totals visible
422+
*/
423+
bool GameController::viewCardTotals(ScreenCoordinate coord)
424+
{
425+
auto font = getGraphicsConfig()["font.path"];
426+
auto fontSize = getGraphicsConfig()["font.size"];
427+
view.showTotals = !view.showTotals;
428+
view.drawCardCount(font, fontSize);
429+
view.drawResourceCount(font, fontSize);
430+
return true;
431+
}
432+
416433

417434
template<int size>
418435
auto negativeArr(std::array<int, size> arr) -> std::array<int, size> {

src/GameView.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ bool ViewElement::handleClick(ScreenCoordinate coord) {
8686
* Constrct a GameView.
8787
* @param model The GameBoard the view is displaying.
8888
*/
89-
GameView::GameView(GameBoard& model) : model(model) {
89+
GameView::GameView(GameBoard& model) : model(model)
90+
{
9091
controlStateText = "Welcome to Wars of Catan";
91-
92+
showTotals = false;
9293
}
9394

9495
/**
@@ -104,7 +105,19 @@ GameView::~GameView() {
104105
* @param font the style of font to use, fontSize the resolution of the font used
105106
* @return void
106107
*/
107-
void GameView::drawCardCount(std::string font, int fontSize){
108+
void GameView::drawCardCount(std::string font, int fontSize)
109+
{
110+
if (showTotals==false)
111+
{
112+
renderText(font, fontSize, {0.97, 0.0}, {1.0, 0.05}, "?"); //Road Building
113+
renderText(font, fontSize, {0.97, 0.05}, {1.0, 0.1}, "?"); //Knight
114+
renderText(font, fontSize, {0.97, 0.1}, {1.0, 0.15}, "?"); //Year of Plenty
115+
renderText(font, fontSize, {0.97, 0.15}, {1.0, 0.2}, "?"); //Monopoly
116+
renderText(font, fontSize, {0.97, 0.2}, {1.0, 0.25}, "?"); //Victory Point
117+
return;
118+
}
119+
120+
108121
renderText(font, fontSize, {0.97, 0.0}, {1.0, 0.05},
109122
toString(model.getCurrentPlayer().getRoadBuildingCards())); //Road Building
110123
renderText(font, fontSize, {0.97, 0.05}, {1.0, 0.1},
@@ -120,7 +133,18 @@ void GameView::drawCardCount(std::string font, int fontSize){
120133
/**
121134
* Draws the count of resources the currentPlayer has
122135
*/
123-
void GameView::drawResourceCount(std::string font, int fontSize){
136+
void GameView::drawResourceCount(std::string font, int fontSize)
137+
{
138+
if(showTotals==false)
139+
{
140+
renderText(font, fontSize, {0.97, 0.35}, {1.0, 0.40}, "?"); //Wood
141+
renderText(font, fontSize, {0.97, 0.40}, {1.0, 0.45}, "?"); //Sheep
142+
renderText(font, fontSize, {0.97, 0.45}, {1.0, 0.50}, "?"); //Ore
143+
renderText(font, fontSize, {0.97, 0.50}, {1.0, 0.55}, "?"); //Brick
144+
renderText(font, fontSize, {0.97, 0.55}, {1.0, 0.60}, "?"); //Wheat
145+
return;
146+
}
147+
124148
renderText(font, fontSize, {0.97, 0.35}, {1.0, 0.40},
125149
toString(model.getCurrentPlayer().getWood())); //Wood
126150
renderText(font, fontSize, {0.97, 0.40}, {1.0, 0.45},

0 commit comments

Comments
 (0)