Skip to content

Commit 1ef8a75

Browse files
committed
Refactored the player class. Left some @todo tags to be rectified once the team has merged their refactorings.
1 parent 6370e2d commit 1ef8a75

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

src/Player.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ bool Player::buyCard(){
290290

291291
/**
292292
* Updates the player's victory points to the amount of points they have.
293+
* @todo Think about merging this with getVictoryPoints()
293294
*/
294295
void Player::updateVictoryPoints()
295296
{
@@ -310,7 +311,7 @@ void Player::updateVictoryPoints()
310311
}
311312

312313
/**
313-
* The number of victory points a player has.
314+
* @return The number of victory points a player has.
314315
*/
315316
int Player::getVictoryPoints()
316317
{
@@ -322,6 +323,7 @@ int Player::getVictoryPoints()
322323
/**
323324
* Acquire a development card.
324325
* @param card An owning pointer to the card the player acquired.
326+
* @return True if the player successfully bought a card, or false if the player had insufficient resources
325327
*/
326328
bool Player::buyCard(std::unique_ptr<DevelopmentCard>& card)
327329
{
@@ -443,7 +445,7 @@ void Player::setGenralModifier()
443445

444446
/**
445447
* Plays a victory point card if it exists. This means, the Player will 'consume' the card to gain a baseVictoryPoint
446-
* @ return true if the card was played, false otherwise
448+
* @return True if the card was played, false otherwise
447449
*/
448450
bool Player::playVictoryCard(){
449451
if(developmentCards[VICTORYPOINT] > 0){
@@ -456,7 +458,7 @@ bool Player::playVictoryCard(){
456458

457459
/**
458460
* Plays a knight card if it exists. This means the player will move the Knight and gain 1 random resource from a player around the robber's new position
459-
* @ param Coordinate of the robber's new position and Player& of the opponent to rob
461+
* @param Coordinate of the robber's new position and Player& of the opponent to rob
460462
* @return true if the card was used, false otherwise
461463
*/
462464
bool Player::playKnight(Coordinate location, Player& opponent){
@@ -477,8 +479,8 @@ bool Player::playKnight(Coordinate location, Player& opponent){
477479

478480
/**
479481
* Plays a year of plenty card if it exists. This means the player will gain 2 of 1 resource of their choice
480-
* @ param the resource the player will recieve
481-
* @ returns true if the card was played, false otherwise
482+
* @param the resource the player will recieve
483+
* @return true if the card was played, false otherwise
482484
*/
483485
bool Player::playYearOfPlenty(int resourceType){
484486
if(resourceType >= 5)
@@ -495,8 +497,8 @@ bool Player::playYearOfPlenty(int resourceType){
495497

496498
/**
497499
* Plays a monopoly card if it exists. This means the player will steal all of 1 resource type from all the other players
498-
* @ param the resource type the player wants to steal
499-
* @ return true if the card was played, false otherwise
500+
* @param The resource type the player wants to steal
501+
* @return True if the card was played, false otherwise
500502
*/
501503
bool Player::playMonopoly(int resourceType){
502504
if (resourceType >= 5)
@@ -515,8 +517,8 @@ bool Player::playMonopoly(int resourceType){
515517

516518
/**
517519
* Plays a road building card if it exists. This means the player will place two roads of their choosing for free
518-
* @ param the start and end Coordinates of the two roads the Player wants to place
519-
* @ return true if the card was played
520+
* @param the start and end Coordinates of the two roads the Player wants to place
521+
* @return true if the card was played
520522
*/
521523
bool Player::playRoadBuilding(Coordinate start1, Coordinate end1, Coordinate start2, Coordinate end2){
522524
if(developmentCards[ROADBUILDING] > 0){
@@ -544,31 +546,37 @@ void Player::setStartingValues(){
544546
developmentCards[ROADBUILDING] = 1;
545547
}
546548

547-
549+
/*
550+
* @todo Refactor this and the following methods
551+
*/
548552
int Player::getDevelopmentCards(int card_type) const{
549553
return developmentCards[card_type];
550554
}
551555

552556
int Player::getVictoryCards() const{
553557
return developmentCards[VICTORYPOINT];
554558
}
559+
555560
int Player::getKnightCards() const{
556561
return developmentCards[KNIGHT];
557562
}
563+
558564
int Player::getYearOfPlentyCards() const{
559565
return developmentCards[YEAROFPLENTY];
560566
}
567+
561568
int Player::getMonopolyCards() const{
562569
return developmentCards[MONOPOLY];
563570
}
571+
564572
int Player::getRoadBuildingCards() const{
565573
return developmentCards[ROADBUILDING];
566574
}
567575

568576
/**
569577
* The player gives all their resources of a specific resource type. Meant to compliment the Monopoly card
570-
* @ param the resource type to give
571-
* @ return the number of resources given
578+
* @param the resource type to give
579+
* @return the number of resources given
572580
*/
573581
int Player::giveAllResources(int resourceType){
574582
int resource_count = resources[resourceType];
@@ -645,12 +653,12 @@ bool Player::makeBankTrade(std::array<int, 5> offer, std::array<int, 5> demand)
645653
}
646654

647655
/**
648-
* picks any one resource at random for robber to steal
649-
* @return type of resource to steal
656+
* Picks any one resource at random for robber to steal
657+
* @return Type of resource to steal
658+
* @todo Make this shit actually random
650659
*/
651660
int Player::getRandomResource()
652661
{
653-
//int total = getWood() + getBrick() + getOre() + getWheat() + getWool();
654662
int randomNo = 0;
655663

656664
if(getWood()!=0 && randomNo <= getWood())
@@ -697,7 +705,7 @@ int Player::getResource(int resourceType) const {
697705

698706
/**
699707
* Determine if the player has a valid (nonnegative) set of resources.
700-
* @return If the player's resources are valid.
708+
* @return True if the player has a non-zero number of resources, or false otherwise
701709
*/
702710

703711
bool Player::checkResources(int resourceList[5])
@@ -758,7 +766,9 @@ int Player::getWool() const
758766
}
759767

760768

761-
769+
/*
770+
*@todo Refactor these add* methods
771+
*/
762772

763773
void Player::addWood(int resource)
764774
{
@@ -824,7 +834,6 @@ void Player::addWool(int resource)
824834
* Adds (or subtracts) the amount of resources a player has
825835
* Param order: wood, brick, ore, wheat, wool
826836
* @param [resource], the number to add (negative to subtract)
827-
*
828837
*/
829838
void Player::addMultiple(int wood, int brick, int ore, int wheat, int wool){
830839
addWood(wood);
@@ -860,7 +869,7 @@ void Player::addResource(int resourceType, int delta) {
860869
/**
861870
* Check to see if a player's resources are equal to the input
862871
* @param [resource]x5 the amount of (wood, brick, ore, wheat, wool) you are checking
863-
* @return bool if the values match
872+
* @return True if the player has the specified amounts of resources, or false otherwise
864873
*/
865874
bool Player::validateResourceAmount(int wood, int brick, int ore, int wheat, int wool){
866875
return wood==getWood() && brick==getBrick() && ore==getOre() && wheat==getWheat() && wool==getWool();
@@ -888,7 +897,7 @@ void Player::accept(GameVisitor& visitor) {
888897
/**
889898
* Compare equality with another player.
890899
* @param player The player to test equality with.
891-
* @return If the other player is equivalent to this player.
900+
* @return True if the other player is equivalent to this player, or false otherwise
892901
*/
893902
bool Player::operator==(const Player& player) const {
894903
return getName() == player.getName() &&

0 commit comments

Comments
 (0)