Skip to content

Commit 5545a84

Browse files
committed
Merge pull request #46 from Databean/knightImplementation
merged
2 parents d718c75 + 86b3bef commit 5545a84

File tree

7 files changed

+116
-8
lines changed

7 files changed

+116
-8
lines changed

include/GameBoard.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include "tinyxml2.h"
1818
#include "Road.h"
1919
#include "GameDice.h"
20+
#include "Deck.h"
21+
22+
#include "DevelopmentCard.h"
23+
2024

2125
class GameVisitor;
2226

@@ -31,7 +35,7 @@ class GameBoard {
3135

3236
GameDice dice;
3337

34-
38+
Deck deck;
3539

3640
std::map<Coordinate, std::vector<std::shared_ptr<Road>>> roads;
3741

@@ -77,6 +81,9 @@ class GameBoard {
7781

7882
void save(std::ostream& out);
7983

84+
void buyCard(Player& owner);
85+
void discardCard(DevelopmentCard * card);
86+
8087
ResourceTile& getResourceTile(Coordinate location) const;
8188

8289
const std::map<Coordinate, std::unique_ptr<ResourceTile>>& getResources() const;

include/GameController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ class GameController {
4040
bool handleSettlementButtonEvent(ScreenCoordinate);
4141
bool handleCityButtonEvent(ScreenCoordinate);
4242
bool handleRoadCardButtonEvent(ScreenCoordinate);
43+
44+
bool handleBuyDevelopmentCardButtonEvent(ScreenCoordinate);
4345
bool handleKnightCardButtonEvent(ScreenCoordinate);
4446
bool handleYearOfPlentyCardButtonEvent(ScreenCoordinate);
4547
bool handleMonopolyCardButtonEvent(ScreenCoordinate);
4648
bool handleVictoryPointCardButtonEvent(ScreenCoordinate);
49+
4750
bool handleCancelButtonEvent(ScreenCoordinate);
4851

4952
bool handleConfirmRoadCard(ScreenCoordinate);

include/GameView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class GameView {
5353

5454
void highlightPoint(ScreenCoordinate & coord);
5555
void drawCardCount(std::string font, int fontSize);
56+
void drawResourceCount(std::string font, int fontSize);
5657

5758
GameView(const GameView& o) = delete;
5859
GameView& operator=(const GameView& o) = delete;
@@ -69,6 +70,7 @@ class GameView {
6970
void addElement(std::unique_ptr<ViewElement> element);
7071
void addElement(int priority, std::unique_ptr<ViewElement>);
7172

73+
7274
std::unique_ptr<ViewElement> removeElement(int priority);
7375
std::unique_ptr<ViewElement> removeElement(const ViewElement*);
7476
std::unique_ptr<ViewElement> removeElement(const ViewElement&);

src/GameBoard.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "CornerPiece.h"
1616
#include "GameDice.h"
17-
1817
#include "Settlement.h"
1918
#include "City.h"
2019
#include "Wonder.h"
@@ -422,6 +421,7 @@ std::vector<CornerPiece*> GameBoard::GetNeighboringCorners(
422421
}
423422

424423

424+
425425
/**
426426
* Checks to make sure the coordinate is within bounds of the board and not a resource tile.
427427
* @param coord The coordinate to check.
@@ -1102,3 +1102,54 @@ void GameBoard::payoutResources(int roll)
11021102
}
11031103
}
11041104
}
1105+
1106+
/**
1107+
* Buys a card drawn from the deck
1108+
*/
1109+
void GameBoard::buyCard(Player& owner){
1110+
if(owner.canBuyCard() && deck.getSize() > 0){
1111+
1112+
DevelopmentCard * card_ptr = deck.drawCard();
1113+
1114+
std::unique_ptr<DevelopmentCard> knight = std::unique_ptr<DevelopmentCard>(new KnightCard());
1115+
std::unique_ptr<DevelopmentCard> victorypoint = std::unique_ptr<DevelopmentCard>(new VictoryPointCard());
1116+
std::unique_ptr<DevelopmentCard> monopoly = std::unique_ptr<DevelopmentCard>(new MonopolyCard());
1117+
std::unique_ptr<DevelopmentCard> yearofplenty = std::unique_ptr<DevelopmentCard>(new YearOfPlentyCard());
1118+
std::unique_ptr<DevelopmentCard> roadbuilding = std::unique_ptr<DevelopmentCard>(new RoadBuildingCard());
1119+
1120+
switch (card_ptr->getType()){
1121+
case KNIGHT:
1122+
owner.buyCard(knight);
1123+
break;
1124+
case VICTORYPOINT:
1125+
owner.buyCard(victorypoint);
1126+
break;
1127+
case MONOPOLY:
1128+
owner.buyCard(monopoly);
1129+
break;
1130+
case YEAROFPLENTY:
1131+
owner.buyCard(yearofplenty);
1132+
break;
1133+
case ROADBUILDING:
1134+
owner.buyCard(roadbuilding);
1135+
break;
1136+
default:
1137+
break;
1138+
}
1139+
1140+
delete(card_ptr);
1141+
}
1142+
}
1143+
1144+
/**
1145+
* Discards a card back into the deck
1146+
*/
1147+
void GameBoard::discardCard(DevelopmentCard * card){
1148+
deck.discard(card);
1149+
}
1150+
1151+
1152+
1153+
1154+
1155+

src/GameController.cpp

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

3939
view.addElement(makeViewButtonColor(std::bind(&GameController::handleCancelButtonEvent, this, _1), {{.95, .95}, {1.0, 1.0}}, std::make_tuple(1.f, 0.0f, 0.f)));
4040

41+
view.addElement(makeViewButtonText(std::bind(&GameController::handleBuyDevelopmentCardButtonEvent, this, _1), {{.85, .23}, {1, .30}}, font, fontSize, "Development Cards"));
4142
view.addElement(makeViewButtonText(std::bind(&GameController::handleRoadCardButtonEvent, this, _1), {{0.85, 0.0}, {0.97, 0.05}}, font, fontSize, "Road Building "));
4243
view.addElement(makeViewButtonText(std::bind(&GameController::handleKnightCardButtonEvent, this, _1), {{0.85, 0.05}, {0.97, 0.10}}, font, fontSize, "Knight "));
4344
view.addElement(makeViewButtonText(std::bind(&GameController::handleYearOfPlentyCardButtonEvent, this, _1), {{0.85, 0.10}, {0.97, 0.15}}, font, fontSize, "Year of Plenty "));
@@ -305,6 +306,11 @@ bool GameController::handleCancelDialogueEvent(ScreenCoordinate coord){
305306
return handleCancelButtonEvent(coord);
306307
}
307308

309+
bool GameController::handleBuyDevelopmentCardButtonEvent(ScreenCoordinate coord){
310+
model.buyCard(model.getCurrentPlayer());
311+
return handleCancelButtonEvent(coord);
312+
}
313+
308314
/**
309315
* Handles a click on the Knight Card button.
310316
* @param coord The place the user clicked

src/GameView.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ GameView::~GameView() {
104104
* @return void
105105
*/
106106
void GameView::drawCardCount(std::string font, int fontSize){
107-
108-
renderText(font, fontSize, {.85, .23}, {1, .30}, "Development Cards");
109-
110107
renderText(font, fontSize, {0.97, 0.0}, {1.0, 0.05},
111108
toString(model.getCurrentPlayer().getRoadBuildingCards())); //Road Building
112109
renderText(font, fontSize, {0.97, 0.05}, {1.0, 0.1},
@@ -119,6 +116,20 @@ void GameView::drawCardCount(std::string font, int fontSize){
119116
toString(model.getCurrentPlayer().getVictoryCards())); //Victory Point
120117
}
121118

119+
void GameView::drawResourceCount(std::string font, int fontSize){
120+
renderText(font, fontSize, {0.97, 0.35}, {1.0, 0.40},
121+
toString(model.getCurrentPlayer().getWood())); //Wood
122+
renderText(font, fontSize, {0.97, 0.40}, {1.0, 0.45},
123+
toString(model.getCurrentPlayer().getWool())); //Sheep
124+
renderText(font, fontSize, {0.97, 0.45}, {1.0, 0.50},
125+
toString(model.getCurrentPlayer().getOre())); //Ore
126+
renderText(font, fontSize, {0.97, 0.50}, {1.0, 0.55},
127+
toString(model.getCurrentPlayer().getBrick())); //Brick
128+
renderText(font, fontSize, {0.97, 0.55}, {1.0, 0.60},
129+
toString(model.getCurrentPlayer().getWheat())); //Wheat
130+
131+
}
132+
122133

123134
/**
124135
* Display the GameBoard to the screen as well as additional ViewElements.
@@ -143,6 +154,7 @@ void GameView::render() {
143154
renderText(font, fontSize, {.2, .9}, {.8, 1}, "Settlers of Catan");
144155

145156
drawCardCount(font, fontSize);
157+
drawResourceCount(font, fontSize);
146158

147159
glFlush();
148160
}

src/Player.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,26 +159,51 @@ bool Player::canBuySettlement(){
159159
return getWood() >= 1 && getBrick() >= 1 && getWheat() >= 1 && getWool() >= 1;
160160
}
161161

162+
/**
163+
* Returns the number of knight cards this player has played
164+
*/
162165
int Player::getArmySize() const{
163166
return armySize;
164167
}
168+
169+
/**
170+
* Returns true if this player has the largest army, false otherwise
171+
*/
165172
bool Player::hasLargestArmy() const{
166173
return largestArmy;
167174
}
175+
176+
/**
177+
* Sets whether or not this player has the largest army
178+
*/
168179
void Player::setLargestArmy(bool newVal){
169180
largestArmy = newVal;
170181
}
171182

183+
/**
184+
* Returns the size of this player's longest road
185+
*/
172186
int Player::getLongestRoadSize() const{
173187
return longestRoadSize;
174188
}
189+
190+
/**
191+
* Returns true if this player has the longet road, false otherwise
192+
*/
175193
bool Player::hasLongestRoad() const{
176194
return longestRoad;
177195
}
196+
197+
/**
198+
* Sets whether or not this player has the longest road
199+
*/
178200
void Player::setLongestRoad(bool newVal){
179201
longestRoad = newVal;
180202
}
181203

204+
/**
205+
* Sets how long this player's longest road is
206+
*/
182207
void Player::setLongestRoadSize(int newVal){
183208
longestRoadSize = newVal;
184209
}
@@ -262,7 +287,7 @@ bool Player::buyCard(){
262287

263288

264289
/**
265-
* Update the player's internal state with their victory states.
290+
* Updates the player's victory points to the amount of points they have.
266291
*/
267292
void Player::updateVictoryPoints()
268293
{
@@ -279,8 +304,7 @@ void Player::updateVictoryPoints()
279304
if(largestArmy){
280305
sum_points+=2;
281306
}
282-
283-
307+
victoryPoints = sum_points;
284308
}
285309

286310
/**
@@ -481,6 +505,7 @@ bool Player::playYearOfPlenty(int resourceType){
481505
if(developmentCards[YEAROFPLENTY] > 0){
482506
developmentCards[YEAROFPLENTY]--;
483507
addResource(resourceType, 2);
508+
board.discardCard(new YearOfPlentyCard());
484509
return true;
485510
}
486511
return false;
@@ -500,6 +525,7 @@ bool Player::playMonopoly(int resourceType){
500525
for(auto& player : board.getPlayers()) {
501526
addResource(resourceType, player->giveAllResources(resourceType));
502527
}
528+
board.discardCard(new MonopolyCard());
503529
return true;
504530
}
505531
return false;
@@ -522,6 +548,7 @@ bool Player::playRoadBuilding(Coordinate start1, Coordinate end1, Coordinate sta
522548
board.PlaceRoad(start2, end2, *this);
523549
}
524550
developmentCards[ROADBUILDING]--;
551+
board.discardCard(new RoadBuildingCard());
525552
return true;
526553
}
527554
}

0 commit comments

Comments
 (0)