Beispiel #1
0
        /* Build a single road segment. Return -1 on fail, 0 on successful
         * construction, and 1 if this segment completed the path. */
        public int BuildRoadSegment(Direction direction, bool roadEndsThere)
        {
            if (!buildingRoad.Extendable)
            {
                // Max length reached
                return(-1);
            }

            buildingRoad.Cost += Pathfinder.ActualCost(Game.Map, buildingRoad.EndPosition, direction);

            AddBuildingRoadSegment(buildingRoad.EndPosition, direction);
            buildingRoad.Extend(Game.Map, direction);

            MapPos destination = 0;
            bool   water       = false;
            int    result      = Game.CanBuildRoad(buildingRoad, player, ref destination, ref water, roadEndsThere);

            if (result <= 0)
            {
                // Invalid construction, undo.
                return(RemoveRoadSegment());
            }

            if (Game.Map.GetObject(destination) == Map.Object.Flag)
            {
                // Existing flag at destination, try to connect.
                if (!Game.BuildRoad(buildingRoad.Copy(), player, true))
                {
                    BuildRoadEnd();
                    return(-1);
                }
                else
                {
                    BuildRoadEnd();
                    UpdateMapCursorPosition(destination);
                    return(1);
                }
            }
            else if (Game.Map.Paths(destination) == 0)
            {
                // No existing paths at destination, build segment.
                UpdateMapCursorPosition(destination);

                if (GetConfig(6)) // pathway scrolling
                {
                    Viewport.MoveToMapPosition(destination, true);
                }
            }
            else
            {
                // TODO fast split path and connect on double click
                return(-1);
            }

            return(0);
        }
        public void Copy_Returns_Road_With_TheSame_Number_Of_Buildings()
        {
            var road = new Road(new[]
            {
                new Point(1, 0),
                new Point(1, 1),
                new Point(1, 2),
                new Point(1, 3)
            });

            road.AddBuilding(new Residence()
            {
                Position = new Point(0, 0)
            });
            road.AddBuilding(new Residence()
            {
                Position = new Point(0, 2)
            });
            road.AddBuilding(new Residence()
            {
                Position = new Point(2, 2)
            });

            var copy = road.Copy();

            Assert.AreEqual(3, copy.Buildings.Count);
        }