/* * Conditions must apply: * no other player's settlement must be present at this location or, within 1 road's distance. * if a settlement exists player must have required resources: * must have required resources: Brick, Wood, Wheat, Sheep * */ public void buildSettlement(Player currentPlayer, bool takeResources, bool connectionCheck) { if (owningPlayer == null) { if (takeResources && !Bank.hasPayment(currentPlayer, Bank.SETTLEMENT_COST)) { throw new BuildError(BuildError.NOT_ENOUGH_RESOURCES); } if (!checkForOtherSettlement()) { throw new BuildError(BuildError.SETTLEMENT_TOO_CLOSE); } if (connectionCheck && !checkForConnection(currentPlayer)) { throw new BuildError(BuildError.NO_CONNECTION_SETTLEMENT); } setOwningPlayer(currentPlayer); currentPlayer.addSettlement(this); } else if (owningPlayer == currentPlayer) { if (!Bank.hasPayment(currentPlayer, Bank.CITY_COST)) { throw new BuildError(BuildError.NOT_ENOUGH_RESOURCES); } if (isCity) { throw new BuildError(BuildError.IS_CITY); } this.isCity = true; this.image = new Bitmap("Resources/city.png"); } else { throw new BuildError(BuildError.LocationOwnedBy(owningPlayer)); } this.Refresh(); }
public void TestGetSettlementLocations() { var target = new Player(); target.incrementCities(); target.generateGrain(); target.generateWool(); target.generateLumber(); target.generateBrick(); target.addSettlement(new Point(4, 4)); List<Point> settlements = target.getSettlementLocations(); Assert.AreEqual(new Point(4, 4), settlements[0]); }