private Node GetObjectUnderMouse() { var currentLoc = SelectRect.Position; if (currentLoc != null) { var zoneUnder = Zones.FirstOrDefault(a => a.Position == currentLoc); var buildingUnder = Buildings.FirstOrDefault(a => a.Position == currentLoc); var roadUnder = Roads.FirstOrDefault(a => a.Position == currentLoc); if (zoneUnder != null) { return(zoneUnder as Node); } else if (buildingUnder != null) { return(buildingUnder as Node); } else if (roadUnder != null) { return(roadUnder as Node); } else { return(null); } } else { return(null); } }
private async Task <bool> AddZone <T> (T zone, 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 (zone is ResidentialZone) { Node z1 = zone as Node; CallDeferred("add_child", zone as Node); var _z = z1 as ResidentialZone; _z.Position = Location; _z.ID = (Zones.Count() < 1) ? 1 : Zones.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1; Zones.Add(_z); } else if (zone is BusinessZone) { Node z1 = zone as Node; CallDeferred("add_child", zone as Node); var _z = z1 as BusinessZone; _z.Position = Location; _z.ID = (Zones.Count() < 1) ? 1 : Zones.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1; Zones.Add(_z); } else if (zone is IndustryZone) { Node z1 = zone as Node; CallDeferred("add_child", zone as Node); var _z = z1 as IndustryZone; _z.Position = Location; _z.ID = (Zones.Count() < 1) ? 1 : Zones.Select(a => a.ID).DefaultIfEmpty(0).Max() + 1; Zones.Add(_z); } return(await Task.FromResult(true).ConfigureAwait(false)); }
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); }