public override string ToString()
 {
     return($"\n\n {nameof(CurrentGeneration)}: {CurrentGeneration}\n" +
            $"{nameof(MainRoad)}: [{MainRoad.Locations.First()}, {MainRoad.Locations.Last()}] \n" +
            $"{nameof(CurrentEpoch)}: {CurrentEpoch}  \n" +
            $"{nameof(Buildings)}: {Buildings.Count()} \n" +
            $"{nameof(Roads)}: {Roads.Count()} \n" +
            $"\n{nameof(LastGeneratedRoads)}: \n" +
            $"{LastGeneratedRoads.Aggregate("", (s1, s2) => s1 + "\n" + s2)}" +
            $"\n{nameof(LastGeneratedBuildings)}: \n" +
            $"{LastGeneratedBuildings.Aggregate("", (s1, s2) => s1 + "\n" + s2)}" +
            $"\n{nameof(LastUpdatedBuildings)}: {LastUpdatedBuildings.Count()} \n" +
            $"{nameof(LastUpdatedRoads)}: {LastUpdatedRoads.Count()} \n" +
            $"{nameof(LastRemovedBuildings)}: {LastRemovedBuildings.Count()}");
 }
    private bool Build <T> (T building, Vector2 Location)
    {
        var existingZone     = Zones.FirstOrDefault(a => a.Position == Location);
        var existingBuilding = Buildings.FirstOrDefault(a => a.Position == Location);
        var existingRoad     = Roads.FirstOrDefault(a => a.Position == Location);

        if (existingZone != null || existingBuilding != null)
        {
            if (existingZone != null)
            {
                DeleteObject(existingZone);
            }
            else if (existingBuilding != null)
            {
                DeleteObject(existingBuilding);
            }
            else if (existingRoad != null)
            {
                DeleteObject(existingRoad);
            }
        }

        if (building is PoliceStation)
        {
            Node z1 = building as Node;
            AddChild(z1);
            var _z = z1 as PoliceStation;
            _z.Position     = Location;
            _z.BuildingType = EnumBuildingTypes.Police;
            _z.ID           = (Buildings.Count() < 1) ? 1 : Buildings.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1;
            Buildings.Add(_z);
        }
        else if (building is UtilityStation)
        {
            Node z1 = building as Node;
            AddChild(building as Node);
            var _z = z1 as UtilityStation;
            _z.Position     = Location;
            _z.BuildingType = EnumBuildingTypes.Util;
            _z.ID           = (Buildings.Count() < 1) ? 1 : Buildings.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1;
            Buildings.Add(_z);
        }
        else if (building is FireStation)
        {
            Node z1 = building as Node;
            AddChild(building as Node);
            var _z = z1 as FireStation;
            _z.Position     = Location;
            _z.BuildingType = EnumBuildingTypes.Fire;
            _z.ID           = (Buildings.Count() < 1) ? 1 : Buildings.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1;
            Buildings.Add(_z);
        }
        else if (building is Park)
        {
            Node z1 = building as Node;
            AddChild(building as Node);
            var _z = z1 as Park;
            _z.Position     = Location;
            _z.BuildingType = EnumBuildingTypes.Park;
            _z.ID           = (Buildings.Count() < 1) ? 1 : Buildings.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1;
            Buildings.Add(_z);
        }
        else if (building is Road)
        {
            Node z1 = building as Node;
            AddChild(building as Node);
            var _z = z1 as Road;
            _z.Position = Location;
            _z.ID       = (Roads.Count() < 1) ? 1 : Roads.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1;
            Roads.Add(_z);
        }
        return(true);
    }
Example #3
0
 private void Roads_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     RoadsPlayed = Roads.Count();
 }