1414
1515#include " CornerPiece.h"
1616
17+ #include " Settlement.h"
1718#include " City.h"
19+ #include " Wonder.h"
1820
1921using std::shared_ptr;
2022using std::random_shuffle;
@@ -199,7 +201,7 @@ GameBoard::GameBoard(istream& in) {
199201 }
200202 }
201203 if (owner == nullptr ) {
202- throw std::runtime_error (" Road is owned by a nonexistant player." );
204+ throw std::runtime_error (" Settlement is owned by a nonexistant player." );
203205 }
204206 PlaceSettlement (location, *owner);
205207 }
@@ -218,7 +220,26 @@ GameBoard::GameBoard(istream& in) {
218220 }
219221 }
220222 if (owner == nullptr ) {
221- throw std::runtime_error (" Road is owned by a nonexistant player." );
223+ throw std::runtime_error (" City is owned by a nonexistant player." );
224+ }
225+ PlaceCity (location, *owner);
226+ }
227+ }
228+
229+ auto wonderElements = doc.RootElement ()->FirstChildElement (" wonders" );
230+ if (wonderElements) {
231+ for (auto wonderElement = wonderElements->FirstChildElement (); wonderElement; wonderElement = wonderElement->NextSiblingElement ()) {
232+ Coordinate location = xmlElementToCoord (*(wonderElement->FirstChildElement (" coordinate" )));
233+
234+ std::string ownerName = wonderElement->FirstChildElement (" owner" )->FirstChild ()->Value ();
235+ Player* owner = nullptr ;
236+ for (auto & playerUnique : players) {
237+ if (playerUnique->getName () == ownerName) {
238+ owner = playerUnique.get ();
239+ }
240+ }
241+ if (owner == nullptr ) {
242+ throw std::runtime_error (" Wonder is owned by a nonexistant player." );
222243 }
223244 PlaceCity (location, *owner);
224245 }
@@ -587,13 +608,32 @@ void GameBoard::PlaceCity(Coordinate location, Player& Owner){
587608
588609}
589610
611+ /* *
612+ * Place a city on the board.
613+ * @param location Where to place it on the board.
614+ * @param Owner The player placing the city.
615+ */
616+ void GameBoard::PlaceWonder (Coordinate location, Player& Owner){
617+ corners[location] = std::unique_ptr<CornerPiece>(new Wonder (*this , location, Owner));
618+
619+ }
620+
590621/* *
591622 * Upgrade a settlement to a city.
592623 * @param location Where the settlement being upgraded is.
593624 */
594625void GameBoard::UpgradeSettlement (Coordinate location){
595626 if (corners.find (location) != corners.end ())
596- corners[location] = std::unique_ptr<CornerPiece>(new City (*corners[location])); // TODO test for memory leak
627+ corners[location] = std::unique_ptr<CornerPiece>(new City (*corners[location])); // TODO test for memory leak
628+ }
629+
630+ /* *
631+ * Upgrade a settlement to a city.
632+ * @param location Where the settlement being upgraded is.
633+ */
634+ void GameBoard::UpgradeToWonder (Coordinate location){
635+ if (corners.find (location) != corners.end ())
636+ corners[location] = std::unique_ptr<CornerPiece>(new Wonder (*corners[location])); // TODO test for memory leak
597637}
598638
599639/* *
0 commit comments