@@ -25,9 +25,10 @@ using std::runtime_error;
2525
2626/* *
2727 * Initialize a player.
28+ * @param board The board the player is playing on.
2829 * @param playerName The name of the player. Should be unique.
2930 */
30- Player::Player (std::string playerName) : name(playerName)
31+ Player::Player (GameBoard& board, std::string playerName) : name(playerName), board(board )
3132{
3233 armySize = 0 ;
3334 longestRoad = 0 ;
@@ -42,9 +43,10 @@ Player::Player(std::string playerName) : name(playerName)
4243
4344/* *
4445 * Construct a player from a serialized tinyxml2::XMLElement.
46+ * @param board The board the player is playing on.
4547 * @param elem The XMLElement to read data from.
4648 */
47- Player::Player (XMLElement* elem)
49+ Player::Player (GameBoard& board, XMLElement* elem) : board(board )
4850{
4951 for (auto & r : resources) {
5052 r = 0 ;
@@ -58,11 +60,11 @@ Player::Player(XMLElement* elem)
5860 XMLElement* cardsElement = elem->FirstChildElement (" cards" );
5961 for (auto cardElem = cardsElement->FirstChildElement (" card" ); cardElem; cardElem = cardElem->NextSiblingElement (" card" )) {
6062 static const map<std::string, std::function<std::unique_ptr<DevelopmentCard>(void )>> typeToCard = {
61- std::pair<std::string, std::function<std::unique_ptr<DevelopmentCard>(void )>>(" knight" , [this ]() -> std::unique_ptr<DevelopmentCard> { return std::unique_ptr<DevelopmentCard>(new KnightCard ()); }),
62- std::pair<std::string, std::function<std::unique_ptr<DevelopmentCard>(void )>>(" victorypoint" , [this ]() -> std::unique_ptr<DevelopmentCard> { return std::unique_ptr<DevelopmentCard>(new VictoryPointCard ()); }),
63- std::pair<std::string, std::function<std::unique_ptr<DevelopmentCard>(void )>>(" yearofplenty" , [this ]() -> std::unique_ptr<DevelopmentCard> { return std::unique_ptr<DevelopmentCard>(new YearOfPlentyCard ()); }),
64- std::pair<std::string, std::function<std::unique_ptr<DevelopmentCard>(void )>>(" monopoly" , [this ]() -> std::unique_ptr<DevelopmentCard> { return std::unique_ptr<DevelopmentCard>(new MonopolyCard ()); }),
65- std::pair<std::string, std::function<std::unique_ptr<DevelopmentCard>(void )>>(" roadbuilding" , [this ]() -> std::unique_ptr<DevelopmentCard> { return std::unique_ptr<DevelopmentCard>(new RoadBuildingCard ()); }),
63+ std::pair<std::string, std::function<std::unique_ptr<DevelopmentCard>(void )>>(" knight" , [&board ]() -> std::unique_ptr<DevelopmentCard> { return std::unique_ptr<DevelopmentCard>(new KnightCard (board )); }),
64+ std::pair<std::string, std::function<std::unique_ptr<DevelopmentCard>(void )>>(" victorypoint" , [&board ]() -> std::unique_ptr<DevelopmentCard> { return std::unique_ptr<DevelopmentCard>(new VictoryPointCard (board )); }),
65+ std::pair<std::string, std::function<std::unique_ptr<DevelopmentCard>(void )>>(" yearofplenty" , [&board ]() -> std::unique_ptr<DevelopmentCard> { return std::unique_ptr<DevelopmentCard>(new YearOfPlentyCard (board )); }),
66+ std::pair<std::string, std::function<std::unique_ptr<DevelopmentCard>(void )>>(" monopoly" , [&board ]() -> std::unique_ptr<DevelopmentCard> { return std::unique_ptr<DevelopmentCard>(new MonopolyCard (board )); }),
67+ std::pair<std::string, std::function<std::unique_ptr<DevelopmentCard>(void )>>(" roadbuilding" , [&board ]() -> std::unique_ptr<DevelopmentCard> { return std::unique_ptr<DevelopmentCard>(new RoadBuildingCard (board )); }),
6668 };
6769 auto typeIt = typeToCard.find (std::string (cardElem->FirstChildElement (" type" )->FirstChild ()->Value ()));
6870 if (typeIt == typeToCard.end ()) {
@@ -162,23 +164,6 @@ int Player::getVictoryPoints()
162164 return victoryPoints;
163165}
164166
165- /* *
166- * The GameBoard that a player is playing on.
167- * @return The board.
168- */
169- GameBoard* Player::getBoard (){
170- return board;
171- }
172-
173- /* *
174- * Assign the Player to a particular GameBoard.
175- * @param newboard The new board they are playing on.
176- */
177- void Player::setBoard (GameBoard * newboard){
178- board = newboard;
179- }
180-
181-
182167/* *
183168 * Acquire a development card.
184169 * @param card An owning pointer to the card the player acquired.
@@ -206,7 +191,7 @@ void Player::buyCard(std::unique_ptr<DevelopmentCard> card)
206191// if(!std::any_of(developmentCards.begin(), developmentCards.end(), cardTester)) {
207192// return;
208193// }
209- // card->playCard();
194+ // card->playCard(board );
210195// if (card->getType() == KNIGHT) {
211196// armySize++;
212197// }
0 commit comments