Skip to content

Commit 96350ba

Browse files
committed
settlements now unplaceable on resource tiles. Upgrade ctor checks for existence of settlement
1 parent b833033 commit 96350ba

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/GameBoard.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,9 @@ int GameBoard::FindLongestRoad_FromPoint(Coordinate curr, const Player & owner,
461461

462462

463463
void GameBoard::PlaceSettlement(Coordinate location, Player& Owner){
464-
corners[location] = std::unique_ptr<CornerPiece>(new Settlement(*this, location, Owner));
464+
if(resources.find(location) == resources.end() && !outOfBounds(location))
465+
corners[location] = std::unique_ptr<CornerPiece>(new Settlement(*this, location, Owner));
466+
465467
}
466468

467469
void GameBoard::PlaceCity(Coordinate location, Player& Owner){
@@ -470,6 +472,7 @@ void GameBoard::PlaceCity(Coordinate location, Player& Owner){
470472
}
471473

472474
void GameBoard::UpgradeSettlement(Coordinate location){
475+
if(corners.find(location) != corners.end())
473476
corners[location] = std::unique_ptr<CornerPiece>(new City(*corners[location])); //TODO test for memory leak
474477
}
475478

tests/test_GameBoard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ TEST(longest_road_simple){
183183
}
184184

185185
TEST(payout_simple) {
186-
/*std::vector<std::unique_ptr<Player>> players {};
186+
std::vector<std::unique_ptr<Player>> players {};
187187
players.emplace_back(new Player("tester"));
188188
Player& test_player = *players[0];
189189
GameBoard * test_board = new GameBoard(std::move(players));
@@ -197,7 +197,7 @@ TEST(payout_simple) {
197197
CHECK(!(test_player.getWheat() || test_player.getWood() ||
198198
test_player.getOre() || test_player.getBrick() || test_player.getWool()));
199199
delete test_board;
200-
delete &test_player;*/
200+
delete &test_player;
201201

202202
}
203203

0 commit comments

Comments
 (0)