Exemplo n.º 1
0
        public void ConstructionTest()
        {
            var edge = new Mock<IEdge>();
            var owner = new Mock<IPlayer>();
            var road = new Road(edge.Object, owner.Object);

            Assert.NotNull(road);
            Assert.Equal(edge.Object, road.Edge);
            Assert.Equal(owner.Object, road.Owner);
        }
Exemplo n.º 2
0
Arquivo: Board.cs Projeto: Corne/VOC
        public IRoad BuildRoad(IEdge edge, IPlayer owner)
        {
            if (edge == null)
                throw new ArgumentNullException(nameof(edge));
            if (owner == null)
                throw new ArgumentNullException(nameof(owner));

            if (!Edges.Contains(edge))
                throw new ArgumentException("Edge does not exist on the board");
            if (roads.Any(r => r.Edge == edge))
                throw new ArgumentException("There already is a road build on the given edge");
            if (Tiles.Where(t => t.IsAdjacentTo(edge)).All(t => t.Rawmaterial == MaterialType.Sea))
                throw new ArgumentException("Can't build roads on sea!");

            var adjacentVertices = Vertices.Where(v => v.IsAdjacentTo(edge));
            var adjacentEdges = Edges.Where(e => e.IsAdjacentTo(edge));
            //CvB Todo: fix readability
            if (establishments.All(e => !adjacentVertices.Contains(e.Vertex) || e.Owner != owner) &&
                roads.All(r => !adjacentEdges.Contains(r.Edge) || r.Owner != owner))
                throw new ArgumentException("Road should have an adjacent establisment or road of the player");

            var road = new Road(edge, owner);
            roads.Add(road);

            logger.Info($"Road build; Player {owner.Name}, {edge.ToString()}");

            return road;
        }