Skip to content

Commit c4c397f

Browse files
committed
Merge remote-tracking branch 'origin/master' into view_dev_cards
2 parents 9bba8bb + 342e99b commit c4c397f

File tree

13 files changed

+547
-96
lines changed

13 files changed

+547
-96
lines changed

include/GameBoard.h

Lines changed: 11 additions & 2 deletions
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

@@ -75,8 +79,13 @@ class GameBoard {
7579

7680
void initializeGame();
7781

82+
GameDice getDice();
83+
7884
void save(std::ostream& out);
7985

86+
void buyCard(Player& owner);
87+
void discardCard(DevelopmentCard * card);
88+
8089
ResourceTile& getResourceTile(Coordinate location) const;
8190

8291
const std::map<Coordinate, std::unique_ptr<ResourceTile>>& getResources() const;
@@ -128,7 +137,7 @@ class GameBoard {
128137

129138
bool testRollChecking(int* rolls);
130139

131-
void moveRobber(Coordinate newRobber);
140+
bool moveRobber(Coordinate newRobber);
132141
Coordinate getRobber() const;
133142
bool canRobberRob(Player& opponent, Coordinate location);
134143

include/GameController.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,19 @@ 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+
50+
bool handleWoodButtonEvent(ScreenCoordinate);
51+
bool handleSheepButtonEvent(ScreenCoordinate);
52+
bool handleWheatButtonEvent(ScreenCoordinate);
53+
bool handleOreButtonEvent(ScreenCoordinate);
54+
bool handleBrickButtonEvent(ScreenCoordinate);
55+
4756
bool handleCancelButtonEvent(ScreenCoordinate);
4857

4958
bool handleConfirmRoadCard(ScreenCoordinate);
@@ -59,6 +68,8 @@ class GameController {
5968
bool hasClickHistory();
6069
int getClickHistorySize();
6170

71+
void robPlayers();
72+
6273
bool handlePlayerClick(ScreenCoordinate, Player&);
6374
bool handleTradeOffer(ScreenCoordinate, Player& initiating, std::array<int, 5>, Player& receiving, std::array<int, 5>);
6475
};

include/GameView.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ 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

58+
std::string controlStateText;
59+
5760
GameView(const GameView& o) = delete;
5861
GameView& operator=(const GameView& o) = delete;
5962
public:
@@ -63,12 +66,15 @@ class GameView {
6366
void render();
6467
bool acceptInput(SDL_Event& event);
6568

69+
void setControlStateText(std::string newText);
70+
6671

6772
void addPointOfInterest(ScreenCoordinate);
6873
void clearPointsOfInterest();
6974
void addElement(std::unique_ptr<ViewElement> element);
7075
void addElement(int priority, std::unique_ptr<ViewElement>);
7176

77+
7278
std::unique_ptr<ViewElement> removeElement(int priority);
7379
std::unique_ptr<ViewElement> removeElement(const ViewElement*);
7480
std::unique_ptr<ViewElement> removeElement(const ViewElement&);

resources/catan_sprite_sheet.bmp

0 Bytes
Binary file not shown.

src/GameBoard.cpp

Lines changed: 78 additions & 14 deletions
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"
@@ -66,6 +65,16 @@ GameBoard::GameBoard(const vector<std::string>& playerNames) {
6665
}
6766
valid = isValidBoard();
6867
}
68+
//moveRobber(Coordinate(0,4));
69+
auto it = getResources().begin();
70+
while(it != getResources().end()) {
71+
if ((it->second)->getType() == DESERT)
72+
moveRobber(it->first);
73+
it++;
74+
}
75+
std::cout << getRobber().first << "\n";
76+
std::cout << getRobber().second << "\n";
77+
6978
}
7079

7180
/**
@@ -127,6 +136,9 @@ GameBoard::GameBoard(const std::vector<std::string>& playerNames, const std::map
127136
currentTurn = 0;
128137
}
129138

139+
GameDice GameBoard::getDice() {
140+
return dice;
141+
}
130142
/**
131143
* Construct a board by reading in an XML representation from a stream.
132144
* @param in The stream to read from.
@@ -400,16 +412,15 @@ std::vector<Settlement*> GameBoard::GetNeighboringSettlements(
400412
* @param location The location to search the neighbors of.
401413
* @return A vector of the corner pieces in the vicinity.
402414
*/
403-
std::vector<CornerPiece*> GameBoard::GetNeighboringCorners(
404-
Coordinate location) const{
405-
static Coordinate adjacentCoordDiffs[] = { Coordinate(0, 1), Coordinate(1,
406-
0), Coordinate(1, -1), Coordinate(0, -1), Coordinate(-1, 0),
407-
Coordinate(-1, 1) };
415+
std::vector<CornerPiece*> GameBoard::GetNeighboringCorners(Coordinate location) const{
416+
static Coordinate adjacentCoordDiffs[] = { Coordinate(0, 1), Coordinate(1,0),
417+
Coordinate(1, -1), Coordinate(0, -1), Coordinate(-1, 0), Coordinate(-1, 1) };
418+
408419
std::vector<CornerPiece*> v;
409420
for (unsigned int i = 0; i < 6; i++) {
410421
const Coordinate& diff = adjacentCoordDiffs[i];
411-
Coordinate adjacentPoint(location.first + diff.first,
412-
location.second + diff.second);
422+
Coordinate adjacentPoint(location.first + diff.first, location.second + diff.second);
423+
413424
auto it = corners.find(adjacentPoint);
414425
if (it != corners.end()) {
415426
GamePiece* piece = it->second.get();
@@ -422,6 +433,7 @@ std::vector<CornerPiece*> GameBoard::GetNeighboringCorners(
422433
}
423434

424435

436+
425437
/**
426438
* Checks to make sure the coordinate is within bounds of the board and not a resource tile.
427439
* @param coord The coordinate to check.
@@ -516,21 +528,22 @@ bool GameBoard::verifyRoadPlacement(Coordinate start, Coordinate end, Player& Ow
516528
* Move the robber to a new coordinate on the board.
517529
* @param newRobber The coordinate to move the robber to.
518530
*/
519-
void GameBoard::moveRobber(Coordinate newRobber) {
531+
bool GameBoard::moveRobber(Coordinate newRobber) {
520532

521533
//Bounds check
522-
if(resources.count(newRobber) > 0)
534+
if(resources.find(newRobber) != resources.end()){
523535
robber = newRobber;
536+
return true;
537+
}
538+
return false;
524539
}
525540

526541
/**
527-
* DOES NOT WORK BECAUSE getNeighboringCorners() does not work
542+
* Returns whether the robber can rob the Player opponent at the recourse tile Coordinate location
543+
* @return true if the robber can rob the opponent, false otherwise
528544
*/
529545
bool GameBoard::canRobberRob(Player& opponent, Coordinate location){
530-
std::cout << GetNeighboringCorners(location).size() << "\n";
531-
532546
for(auto corner : GetNeighboringCorners(location)){
533-
std::cout << corner->getOwner().getName() << "derp\n";
534547
if(corner->getOwner() == opponent){
535548
return true;
536549
}
@@ -1102,3 +1115,54 @@ void GameBoard::payoutResources(int roll)
11021115
}
11031116
}
11041117
}
1118+
1119+
/**
1120+
* Buys a card drawn from the deck
1121+
*/
1122+
void GameBoard::buyCard(Player& owner){
1123+
if(owner.canBuyCard() && deck.getSize() > 0){
1124+
1125+
DevelopmentCard * card_ptr = deck.drawCard();
1126+
1127+
std::unique_ptr<DevelopmentCard> knight = std::unique_ptr<DevelopmentCard>(new KnightCard());
1128+
std::unique_ptr<DevelopmentCard> victorypoint = std::unique_ptr<DevelopmentCard>(new VictoryPointCard());
1129+
std::unique_ptr<DevelopmentCard> monopoly = std::unique_ptr<DevelopmentCard>(new MonopolyCard());
1130+
std::unique_ptr<DevelopmentCard> yearofplenty = std::unique_ptr<DevelopmentCard>(new YearOfPlentyCard());
1131+
std::unique_ptr<DevelopmentCard> roadbuilding = std::unique_ptr<DevelopmentCard>(new RoadBuildingCard());
1132+
1133+
switch (card_ptr->getType()){
1134+
case KNIGHT:
1135+
owner.buyCard(knight);
1136+
break;
1137+
case VICTORYPOINT:
1138+
owner.buyCard(victorypoint);
1139+
break;
1140+
case MONOPOLY:
1141+
owner.buyCard(monopoly);
1142+
break;
1143+
case YEAROFPLENTY:
1144+
owner.buyCard(yearofplenty);
1145+
break;
1146+
case ROADBUILDING:
1147+
owner.buyCard(roadbuilding);
1148+
break;
1149+
default:
1150+
break;
1151+
}
1152+
1153+
delete(card_ptr);
1154+
}
1155+
}
1156+
1157+
/**
1158+
* Discards a card back into the deck
1159+
*/
1160+
void GameBoard::discardCard(DevelopmentCard * card){
1161+
deck.discard(card);
1162+
}
1163+
1164+
1165+
1166+
1167+
1168+

0 commit comments

Comments
 (0)