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); }