public IEstablishment BuildEstablishment(IVertex vertex, IPlayer owner) { if (vertex == null) throw new ArgumentNullException(nameof(vertex)); if (owner == null) throw new ArgumentNullException(nameof(owner)); if (!Vertices.Contains(vertex)) throw new ArgumentException("Did not find the passed vertex on the board"); if (establishments.Any(e => e.Vertex == vertex)) throw new ArgumentException("Invalid vertex, already an establishment here"); var vertices = Vertices.Where(v => v.IsAdjacentTo(vertex)); var tiles = Tiles.Where(t => t.IsAdjacentTo(vertex)); if (establishments.Any(e => vertices.Contains(e.Vertex))) throw new ArgumentException("Invalid vertex, establishment can't be placed next to another establishment"); if (tiles.All(t => t.Rawmaterial == MaterialType.Sea)) throw new ArgumentException("Can't place an establishment on sea!"); if (establishments.Count(e => e.Owner == owner) >= 2 && roads.Where(r => r.Owner == owner).All(r => !r.Edge.IsAdjacentTo(vertex))) throw new InvalidOperationException("Each player can only build 2 houses without adjacent roads!"); var establishment = new Establishment(owner, vertex); establishments.Add(establishment); logger.Info($"Establisment Build; Player {owner.Name}, {vertex.ToString()}"); return establishment; }
public void ConstructionSetsLevelToSettlement() { var player = new Mock<IPlayer>(); var vertex = new Mock<IVertex>(); var establisment = new Establishment(player.Object, vertex.Object); Assert.Equal(EstablishmentLevel.Settlement, establisment.Level); }
public void UpdgradeFailsIfLevelAlreadyCity() { var player = new Mock<IPlayer>(); var vertex = new Mock<IVertex>(); var establisment = new Establishment(player.Object, vertex.Object); establisment.Upgrade(); Assert.Throws<InvalidOperationException>(() => establisment.Upgrade()); }
public void UpgradeSetsLevelToCity() { var player = new Mock<IPlayer>(); var vertex = new Mock<IVertex>(); var establisment = new Establishment(player.Object, vertex.Object); establisment.Upgrade(); Assert.Equal(EstablishmentLevel.City, establisment.Level); }
public void HarvestThrowsExceptionIfTileIsNotAdjacent() { var player = new Mock<IPlayer>(); var vertex = new Mock<IVertex>(); var tile = new Mock<ITile>(); vertex.Setup(v => v.IsAdjacentTo(tile.Object)).Returns(false); var establisment = new Establishment(player.Object, vertex.Object); Assert.Throws<ArgumentException>(() => establisment.Harvest(tile.Object)); }
public void HarvestValidatesThatEstbalismentAdjacentsTile() { var player = new Mock<IPlayer>(); var vertex = new Mock<IVertex>(); var tile = new Mock<ITile>(); vertex.Setup(v => v.IsAdjacentTo(tile.Object)).Returns(true); var establisment = new Establishment(player.Object, vertex.Object); establisment.Harvest(tile.Object); vertex.Verify(v => v.IsAdjacentTo(tile.Object)); }
public void HarvestAddsXResourcesToPlayer() { var player = new Mock<IPlayer>(); var vertex = new Mock<IVertex>(); var tileMock = new Mock<ITile>(); tileMock.Setup(t => t.Rawmaterial).Returns(MaterialType.Grain); tileMock.Setup(t => t.Farm()).Returns(new Mock<IRawMaterial>().Object); var tile = tileMock.Object; vertex.Setup(v => v.IsAdjacentTo(tile)).Returns(true); var establisment = new Establishment(player.Object, vertex.Object); establisment.Harvest(tile); player.Verify(p => p.AddResources(It.IsAny<IRawMaterial>()), Times.Once()); }
public void EstablismentShouldFarmTile() { var player = new Mock<IPlayer>(); var vertex = new Mock<IVertex>(); var tileMock = new Mock<ITile>(); tileMock.Setup(t => t.Rawmaterial).Returns(MaterialType.Grain); var tile = tileMock.Object; vertex.Setup(v => v.IsAdjacentTo(tile)).Returns(true); var establisment = new Establishment(player.Object, vertex.Object); establisment.Harvest(tile); tileMock.Verify(t => t.Farm()); }