public void AddLand(Land land) { if (Lands.Any(lnd => lnd.Equals(land))) { return; } Lands.Add(land); }
/// <summary> /// Adds a GeoJson file to the layer. /// </summary> /// <param name="file"></param> public void AddFile(GeoJsonFile file) { if (file.Features is null) { throw new Exception( $"The {nameof(GeoJsonFile.Features)} property is required to build a {nameof(CoreMap<TDrawingContext>)} instance. " + $"Ensure the property is not null."); } foreach (var feature in file.Features) { if (feature.Geometry is null || feature.Geometry.Coordinates is null) { continue; } var name = (feature.Properties?["name"] ?? "?").ToLowerInvariant(); var shortName = (feature.Properties?["shortName"] ?? "?").ToLowerInvariant(); var setOf = (feature.Properties?["setOf"] ?? "?").ToLowerInvariant(); var definition = new LandDefinition(shortName, name, setOf); var dataCollection = new List <LandData>(); foreach (var geometry in feature.Geometry.Coordinates) { foreach (var segment in geometry) { var data = new LandData(segment); if (data.MaxBounds[0] > definition.MaxBounds[0]) { definition.MaxBounds[0] = data.MaxBounds[0]; } if (data.MinBounds[0] < definition.MinBounds[0]) { definition.MinBounds[0] = data.MinBounds[0]; } if (data.MaxBounds[1] > definition.MaxBounds[1]) { definition.MaxBounds[1] = data.MaxBounds[1]; } if (data.MinBounds[1] < definition.MinBounds[1]) { definition.MinBounds[1] = data.MinBounds[1]; } dataCollection.Add(data); } } definition.Data = dataCollection.OrderByDescending(x => x.BoundsHypotenuse).ToArray(); Lands.Add(shortName, definition); } }
public void LandInitialization() { var random = new Random(Seed); for (int y = 0; y < 20; y++) { for (int x = 0; x < 20; x++) { var n = random.Next(1, 18); var plane = (n > 12 && n > 16) ? new City() : (n > 12) ? new Town() : new Plane(); foreach (Producer pr in Producers) { plane.Producers.Add(pr, 0); } if (plane is City) { plane.Gold = random.Next(300, 1500) * 2; for (int i = 0; i < random.Next(2, 5); i++) { var p = random.Next(0, Producers.Count); var l = random.Next(1, 4); plane.Producers[Producers[p]] += l; plane.Shop = new Shop(); plane.Shop.Gold = plane.Gold; } } else if (plane is Town) { plane.Gold = random.Next(300, 1500); var p = random.Next(0, Producers.Count); var l = random.Next(1, 2); plane.Producers[Producers[p]] = l; plane.Shop = new Shop(); plane.Shop.Gold = plane.Gold; } if (plane is Town || plane is City) { foreach (Item item in Resources) { Item it = item; int r = plane is City?random.Next(10, 100) : random.Next(5, 50); it.ActualValue = (r / 10 * it.BaseValue) - (plane.Producers.First(p => p.Key.Resource.Name == it.Name).Value *plane.Producers.First(p => p.Key.Resource.Name == it.Name).Key.ResourcePerDay); plane.Shop.Items.Add(it, r); } } Lands.Add(new Point(x, y), plane); } } }
async void GetLands() { //IsBusy = true; try { Lands.Clear(); var landList = await remoteService.GetAllProperty(); foreach (var item in landList) { if (item.ItemType.ToLower() == "land") { if (Lands.Count < 3) { Lands.Add(item); } } } } catch (Exception ex) { Debug.WriteLine(ex); } }