Skip to content

Commit 826f9ef

Browse files
committed
Merge pull request #25 from Databean/trading_complete
Fixed bugs in Ankit's code, plus some refactoring.
2 parents f5a46ad + 52fb3be commit 826f9ef

16 files changed

+456
-417
lines changed

include/Deck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Deck {
2727
void reshuffleDeck();
2828

2929
public:
30-
Deck();
30+
Deck(GameBoard& board);
3131
virtual ~Deck();
3232

3333
int getSize();

include/DevelopmentCard.h

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,93 +20,82 @@
2020
enum DevCardType { KNIGHT, VICTORYPOINT, YEAROFPLENTY, MONOPOLY, ROADBUILDING };
2121

2222

23-
/**
24-
* A card which can be held in a player's hand and be used to perform an action.
25-
*/
23+
2624
class DevelopmentCard {
2725

28-
private:
29-
Player* owner;
26+
protected:
3027
DevCardType type;
28+
GameBoard& board;
3129
public:
32-
DevelopmentCard(Player* player);
30+
DevelopmentCard(GameBoard& board);
3331
virtual ~DevelopmentCard();
3432

3533
virtual DevCardType getType() const = 0;
36-
virtual void playCard() = 0;
3734

38-
virtual Player* getOwner();
3935
virtual void accept(GameVisitor& visitor);
4036
virtual bool operator==(const DevelopmentCard&);
4137
};
4238

43-
/**
44-
* A development card used to move the robber and take a resource from another player.
45-
*/
39+
40+
4641
class KnightCard : public DevelopmentCard {
4742
private:
4843

4944
public:
50-
KnightCard(Player* player);
45+
KnightCard(GameBoard& board);
5146
// virtual ~KnightCard();
5247

5348
virtual DevCardType getType() const;
54-
virtual void playCard();
49+
void playCard(Player *player, Coordinate target);
5550

5651
};
5752

58-
/**
59-
* A development card that gives a permanent victory point on usage.
60-
*/
53+
54+
6155
class VictoryPointCard : public DevelopmentCard {
6256
public:
63-
VictoryPointCard(Player* player);
57+
VictoryPointCard(GameBoard& board);
6458
// virtual ~VictoryPointCard();
6559

6660
virtual DevCardType getType() const;
67-
virtual void playCard();
6861

6962
};
7063

71-
/**
72-
* A development card used to retrieve two resources of any type from the bank.
73-
*/
64+
7465
class YearOfPlentyCard : public DevelopmentCard {
7566
public:
76-
YearOfPlentyCard(Player* player);
67+
YearOfPlentyCard(GameBoard& board);
7768
// virtual ~YearOfPlentyCard();
7869

7970
virtual DevCardType getType() const;
80-
virtual void playCard();
71+
void playCard(Player *player, int rType1, int rType2);
8172

8273
};
8374

84-
/**
85-
* A development card used to take all resources of a particular type from all players.
86-
*/
75+
76+
77+
8778
class MonopolyCard : public DevelopmentCard {
8879
public:
89-
MonopolyCard(Player* player);
80+
MonopolyCard(GameBoard& board);
9081
// virtual ~MonopolyCard();
9182

9283
virtual DevCardType getType() const;
93-
virtual void playCard();
84+
void playCard(Player *player, int rType);
9485

9586
};
9687

97-
/**
98-
* A development card used to build two roads at no cost.
99-
*/
88+
89+
10090
class RoadBuildingCard : public DevelopmentCard {
10191
private:
10292

10393
public:
104-
RoadBuildingCard(Player* player);
94+
RoadBuildingCard(GameBoard& board);
10595
// virtual ~RoadBuildingCard();
10696

10797
virtual DevCardType getType() const;
108-
virtual void playCard();
109-
void playCard(Coordinate start1, Coordinate end1, Coordinate start2, Coordinate end2);
98+
void playCard(Player* player, Coordinate start1, Coordinate end1, Coordinate start2, Coordinate end2);
11099
};
111100

112101

include/GameBoard.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ class GameBoard {
3535
std::vector<std::unique_ptr<Player>> players;
3636
Coordinate robber;
3737

38-
38+
3939
void addResource(int x, int y, resourceType res, int val);
4040
bool checkRolls(int* rolls);
41-
41+
4242
bool isValidBoard() const;
43-
43+
4444

4545
bool verifyRoadPlacement(Coordinate start, Coordinate end, Player& Owner) const;
4646
bool outOfBounds(const Coordinate& coord) const;
@@ -52,7 +52,7 @@ class GameBoard {
5252

5353
void removeRoadEnd(std::shared_ptr<Road> startRoad);
5454
int FindLongestRoad_FromPoint(Coordinate curr, const Player & owner, std::map<Coordinate, bool>& marked, std::map<Road*, bool>& markedRoads, int length) const;
55-
55+
5656
void createRing(Coordinate topRight, int sideLength, std::vector<resourceType>& resources, std::vector<int>& rolls);
5757
void insertTile(Coordinate location, std::vector<resourceType>& resources, std::vector<int>& rolls);
5858

@@ -61,15 +61,15 @@ class GameBoard {
6161
void payoutResources(int roll);
6262

6363
public:
64-
GameBoard(std::vector<std::unique_ptr<Player>>&& players);
65-
GameBoard(std::vector<std::unique_ptr<Player>>&& players, const std::map<Coordinate, std::pair<resourceType, int>>& resourceLocations);
64+
GameBoard(const std::vector<std::string>& playerNames);
65+
GameBoard(const std::vector<std::string>& playerNames, const std::map<Coordinate, std::pair<resourceType, int>>& resourceLocations);
6666
GameBoard(std::istream& in);
6767
GameBoard(GameBoard&) = delete;
6868
~GameBoard();
6969
GameBoard& operator=(GameBoard&) = delete;
70-
70+
7171
void save(std::ostream& out);
72-
72+
7373
ResourceTile& getResourceTile(Coordinate location) const;
7474

7575
const std::map<Coordinate, std::unique_ptr<ResourceTile>>& getResources() const;
@@ -78,7 +78,7 @@ class GameBoard {
7878

7979
const std::shared_ptr<Road> getRoad(Coordinate start, Coordinate end) const;
8080
const std::vector<std::shared_ptr<Road>>& getRoads(Coordinate loc) const;
81-
81+
8282
int FindLongestRoad(const Player & owner) const;
8383

8484
std::vector<Settlement*> GetNeighboringSettlements(Coordinate location) const;
@@ -96,13 +96,16 @@ class GameBoard {
9696
//void PlaceSettlement(Coordinate location, Player& Owner);
9797
void PlaceCity(Coordinate location, Player& Owner);
9898
bool PlaceRoad(Coordinate start, Coordinate end, Player& Owner);
99-
99+
100100
void accept(GameVisitor& visitor);
101-
101+
102102
bool operator==(const GameBoard& other) const;
103-
103+
104104
const std::vector<std::unique_ptr<Player>>& getPlayers() const;
105-
105+
106+
int getNoOfPlayers();
107+
Player& getPlayer(int index);
108+
106109
bool testRollChecking(int* rolls);
107110

108111
void moveRobber(Coordinate newRobber);

include/Player.h

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ const int WOOL_INDEX = 4;
2727

2828
class DevelopmentCard;
2929
class Deck;
30-
class GameBoard;
3130

3231

33-
/**
34-
* One of the players interacting with the Settlers of Catan game. Contains her name, victory points,
35-
* development cards, and resources.
36-
*/
32+
33+
3734
class Player {
3835
private:
3936
std::string name;
@@ -43,16 +40,17 @@ class Player {
4340
int armySize;
4441
int longestRoad;
4542
int victoryPoints;
46-
GameBoard* board;
43+
GameBoard& board;
4744
int resources[5];
45+
int tradeModifiers[5];
4846

4947

50-
48+
void tradeWithBank(int offer[], int demand[]);
5149

5250
public:
5351

54-
Player(std::string playerName);
55-
Player(tinyxml2::XMLElement*);
52+
Player(GameBoard& board, std::string playerName);
53+
Player(GameBoard& board, tinyxml2::XMLElement*);
5654
~Player();
5755

5856
int getVictoryPoints();
@@ -66,18 +64,28 @@ class Player {
6664
void buyCard(std::unique_ptr<DevelopmentCard> card);
6765
std::string getName() const;
6866

69-
GameBoard* getBoard();
70-
void setBoard(GameBoard* newboard);
71-
72-
void playCard(DevelopmentCard* card);
67+
// void playCard(int index);
68+
// void playCard(DevelopmentCard* card);
7369

7470
bool canBuyRoad();
7571
bool buyRoad();
7672

73+
void setWoodModifier();
74+
void setBrickModifier();
75+
void setOreModifier();
76+
void setWheatModifier();
77+
void setWoolModifier();
78+
79+
void setGenralModifier(); //3:1 port
80+
81+
bool offerBankTrade(int offer[], int demand[]);
82+
7783
bool offerTrade(Player* p, int offer[], int demand[]);
7884
bool recieveOffer(Player* p, int offer[], int demand[]);
7985
bool acceptOffer(Player* p, int offer[], int demand[]);
8086

87+
int getRandomResource();
88+
8189
bool checkResources(int resourceList[]);
8290

8391
int getWood() const;
@@ -92,6 +100,7 @@ class Player {
92100
void addWheat(int resource);
93101
void addWool(int resource);
94102

103+
int getResource(int resourceType) const; //
95104
void addResource(int resourceType, int delta);
96105

97106
void accept(GameVisitor& visitor);

include/Serialization.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class XMLVisitor : public GameVisitor {
1919
std::map<std::string, tinyxml2::XMLElement*> playerElementMap;
2020
std::set<Road*> serializedRoads;
2121

22+
Player* lastPlayer;
23+
2224
tinyxml2::XMLElement* coordinateElement(const Coordinate& c);
2325
public:
2426
XMLVisitor();

src/Deck.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@
1111
/**
1212
* Construct a Deck with the standard cards available in the Settlers of Catan game.
1313
*/
14-
Deck::Deck()
14+
Deck::Deck(GameBoard& board)
1515
{
1616
// TODO Auto-generated constructor stub
1717
for(int i = 0; i < 15; i++)
1818
{
19-
DevelopmentCard* card = new KnightCard(NULL);
19+
DevelopmentCard* card = new KnightCard(board);
2020
this->deck.push_back(card);
2121
}
2222
for(int i = 0; i < 4; i++)
2323
{
24-
DevelopmentCard* card = new VictoryPointCard(NULL);
24+
DevelopmentCard* card = new VictoryPointCard(board);
2525
this->deck.push_back(card);
2626
}
2727
for(int i = 0; i < 2; i++)
2828
{
29-
DevelopmentCard* card = new YearOfPlentyCard(NULL);
29+
DevelopmentCard* card = new YearOfPlentyCard(board);
3030
this->deck.push_back(card);
3131
}
3232
for(int i = 0; i < 2; i++)
3333
{
34-
DevelopmentCard* card = new MonopolyCard(NULL);
34+
DevelopmentCard* card = new MonopolyCard(board);
3535
this->deck.push_back(card);
3636
}
3737
for(int i = 0; i < 2; i++)
3838
{
39-
DevelopmentCard* card = new RoadBuildingCard(NULL);
39+
DevelopmentCard* card = new RoadBuildingCard(board);
4040
this->deck.push_back(card);
4141
}
4242

0 commit comments

Comments
 (0)