Skip to content

Commit ef42686

Browse files
Kyle GrageKyle Grage
authored andcommitted
Updates to player class & test_Player partially implemented
1 parent 670e903 commit ef42686

File tree

3 files changed

+318
-7
lines changed

3 files changed

+318
-7
lines changed

include/Player.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ class Player {
5353
Player(GameBoard& board, tinyxml2::XMLElement*);
5454
~Player();
5555

56+
int getArmySize();
57+
int getLongestRoad();
5658
int getVictoryPoints();
59+
5760
void updateVictoryPoints();
5861

5962
int getVictoryPointsWithoutCards();
@@ -75,14 +78,21 @@ class Player {
7578
bool buyCity();
7679
bool canBuyWonder();
7780
bool buyWonder();
81+
bool canBuyCard();
82+
bool buyCard();
7883

84+
int getWoodModifier();
7985
void setWoodModifier();
86+
int getBrickModifier();
8087
void setBrickModifier();
88+
int getOreModifier();
8189
void setOreModifier();
90+
int getWheatModifier();
8291
void setWheatModifier();
92+
int getWoolModifier();
8393
void setWoolModifier();
8494

85-
void setGenralModifier(); //3:1 port
95+
void setGeneralModifier(); //3:1 port
8696

8797
bool offerBankTrade(int offer[], int demand[]);
8898

src/Player.cpp

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ bool Player::buyRoad(){
117117

118118
/**
119119
* Determine if the player has enough resources to buy a settlement.
120-
* @return True if the player has enough resources to buy a road, false otherwise
120+
* @return True if the player has enough resources to buy a settlement, false otherwise
121121
*/
122122
bool Player::canBuySettlement(){
123123
return getWood() >= 1 && getBrick() >= 1 && getWheat() >= 1 && getWool() >= 1;
@@ -137,7 +137,7 @@ bool Player::buySettlement(){
137137

138138
/**
139139
* Determine if the player has enough resources to buy a city.
140-
* @return True if the player has enough resources to buy a road, false otherwise
140+
* @return True if the player has enough resources to buy a city, false otherwise
141141
*/
142142
bool Player::canBuyCity(){
143143
return getWheat() >= 2 && getOre() >= 3;
@@ -156,7 +156,7 @@ bool Player::buyCity(){
156156

157157
/**
158158
* Determine if the player has enough resources to buy a wonder.
159-
* @return True if the player has enough resources to buy a road, false otherwise
159+
* @return True if the player has enough resources to buy a wonder, false otherwise
160160
*/
161161
bool Player::canBuyWonder(){
162162
return getWood() >= 5 && getBrick() >= 5 && getWheat() >= 5 && getWool() >= 5 && getOre() >= 5;
@@ -174,6 +174,26 @@ bool Player::buyWonder(){
174174
return false;
175175
}
176176

177+
/**
178+
* Determine if the player has enough resources to buy a card.
179+
* @return True if the player has enough resources to buy a card, false otherwise
180+
*/
181+
bool Player::canBuyCard(){
182+
return getWheat() >= 1 && getWool() >= 1 && getOre() >= 1;
183+
}
184+
185+
/**
186+
* Subtracts the cost of a card from a player's resources if they have enough
187+
* @return true if the resources were subtracted, false otherwise
188+
*/
189+
bool Player::buyCard(){
190+
if(canBuySettlement()){
191+
addMultiple(0,0,-1,-1,-1);
192+
return true;
193+
}
194+
return false;
195+
}
196+
177197

178198

179199
/**
@@ -212,6 +232,14 @@ int Player::getVictoryPointCards()
212232
return retVal;
213233
}
214234

235+
int Player::getArmySize(){
236+
return armySize;
237+
}
238+
239+
int Player::getLongestRoad(){
240+
return longestRoad;
241+
}
242+
215243

216244
/**
217245
* The number of victory points a player has.
@@ -226,9 +254,13 @@ int Player::getVictoryPoints()
226254
* Acquire a development card.
227255
* @param card An owning pointer to the card the player acquired.
228256
*/
229-
void Player::buyCard(std::unique_ptr<DevelopmentCard> card)
257+
void Player::buyCard(std::unique_ptr<DevelopmentCard> card);
230258
{
231-
developmentCards.push_back(std::move(card));
259+
if(canBuyCard()){
260+
buyCard();
261+
developmentCards.push_back(std::move(card));
262+
}
263+
232264
}
233265

234266

@@ -257,6 +289,13 @@ void Player::buyCard(std::unique_ptr<DevelopmentCard> card)
257289
// std::remove_if(developmentCards.begin(), developmentCards.end(), cardTester);
258290
//}
259291

292+
/**
293+
* Gets the current modifier for trading wood
294+
* @return int, the trading value for wood
295+
*/
296+
int Player::getWoodModifier(){
297+
return tradeModifiers[WOOD_INDEX];
298+
}
260299

261300
/**
262301
* Sets the trade modifier for Wood to 2:1
@@ -266,6 +305,14 @@ void Player::setWoodModifier()
266305
tradeModifiers[WOOD_INDEX] = 2;
267306
}
268307

308+
/**
309+
* Gets the current modifier for trading brick
310+
* @return int, the trading value for brick
311+
*/
312+
int Player::getBrickModifier(){
313+
return tradeModifiers[BRICK_INDEX];
314+
}
315+
269316
/**
270317
* Sets the trade modifier for Brick to 2:1
271318
*/
@@ -274,6 +321,14 @@ void Player::setBrickModifier()
274321
tradeModifiers[BRICK_INDEX] = 2;
275322
}
276323

324+
/**
325+
* Gets the current modifier for trading ore
326+
* @return int, the trading value for ore
327+
*/
328+
int Player::getOreModifier(){
329+
return tradeModifiers[ORE_INDEX];
330+
}
331+
277332
/**
278333
* Sets the trade modifier for Ore to 2:1
279334
*/
@@ -282,6 +337,14 @@ void Player::setOreModifier()
282337
tradeModifiers[ORE_INDEX] = 2;
283338
}
284339

340+
/**
341+
* Gets the current modifier for trading wheat
342+
* @return int, the trading value for wheat
343+
*/
344+
int Player::getWheatModifier(){
345+
return tradeModifiers[WHEAT_INDEX];
346+
}
347+
285348
/**
286349
* Sets the trade modifier for Wheat to 2:1
287350
*/
@@ -290,6 +353,14 @@ void Player::setWheatModifier()
290353
tradeModifiers[WHEAT_INDEX] = 2;
291354
}
292355

356+
/**
357+
* Gets the current modifier for trading wool
358+
* @return int, the trading value for wool
359+
*/
360+
int Player::getWoolModifier(){
361+
return tradeModifiers[WOOL_INDEX];
362+
}
363+
293364
/**
294365
* Sets the trade modifier for Wool to 2:1
295366
*/
@@ -301,7 +372,7 @@ void Player::setWoolModifier()
301372
/**
302373
* Sets the trade modifier for all resources to 3:1
303374
*/
304-
void Player::setGenralModifier()
375+
void Player::setGeneralModifier()
305376
{
306377
for(int i =0; i<5; i++)
307378
{

0 commit comments

Comments
 (0)