private async void getStopsInfo() { string errorMessage = null; try { double minLat = 90; double maxLat = -90; double minLng = 180; double maxLng = -180; string webresponse = await Network.StopsByService(Service.ServiceId); List <Stop> rootObject = JsonConvert.DeserializeObject <List <Stop> >(webresponse); foreach (Stop s in rootObject) { StopsList.Add(s); Lines.Add(new BasicGeoposition() { Latitude = s.Location.Lat, Longitude = s.Location.Lng }); if (s.Location.Lat > maxLat) { maxLat = s.Location.Lat; } if (s.Location.Lat < minLat) { minLat = s.Location.Lat; } if (s.Location.Lng > maxLng) { maxLng = s.Location.Lng; } if (s.Location.Lng < minLng) { minLng = s.Location.Lng; } } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { MapPolyline CourseLines = new MapPolyline(); CourseLines.Path = new Geopath(Lines); CourseLines.StrokeColor = Colors.DodgerBlue; CourseLines.StrokeThickness = 5; MapControl.MapElements.Add(CourseLines); }); BasicGeoposition nw = new BasicGeoposition() { Latitude = maxLat, Longitude = minLng }; BasicGeoposition se = new BasicGeoposition() { Latitude = minLat, Longitude = maxLng }; GeoboundingBox box = new GeoboundingBox(nw, se); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await MapControl.TrySetViewBoundsAsync(box, new Thickness(2, 2, 2, 2), MapAnimationKind.Bow); }); } catch (Exception ex) { errorMessage = ex.Message; } if (errorMessage != null) { MessageDialog msg = new MessageDialog("Houve algum problema durante a requisição ao servidor. Por favor, verifique se o aparelho está conectado à internet e tente novamente.", "Você está conectado à internet?"); await msg.ShowAsync(); } }
public Maze GenerateMaze(int with = 30, int height = 20) { //reset ID of stop Stop.Reset(); //creating all stops into maze for (int j = 0; j < height; j++) { for (int i = 0; i < with; i++) { var stop = new Stop() { CordY = j, CordX = i, Name = $"Stop-{i}-{j}", IsHidden = i > (with * 0.4) }; StopsList.Add(stop); } } StartStop = StopsList[0]; //Generating real maze #region var unvisitedStops = new List <Stop>(StopsList); //get start Stop Stack myStack = new Stack(); var current = unvisitedStops.SingleOrDefault(x => x.CordX == 0 && x.CordY == 0); if (current is null) { return(this); } unvisitedStops.Remove(current); while (unvisitedStops.Any()) { var neighbors = unvisitedStops.Where(x => Math.Sqrt(Math.Pow(current.CordX - x.CordX, 2) + Math.Pow(current.CordY - x.CordY, 2)) <= 1).ToList(); if (!neighbors.Any()) { if (myStack.Count <= 0) { return(this); } #region //connecting death end var lastneighbors = StopsList.Where(x => Math.Abs(Math.Sqrt(Math.Pow(current.CordX - x.CordX, 2) + Math.Pow(current.CordY - x.CordY, 2)) - 1) < 0.0001 && !RoadsList.Any(s => s.ToStop.Id == current.Id && s.FromStop.Id == x.Id) ).ToList(); if (lastneighbors.Any() && (lastneighbors.Count() > 2 || _rnd.Next(101) < intenconectionChance)) { var randStop2 = _rnd.Next(lastneighbors.Count()); InterConnectStops(current, lastneighbors[randStop2]); } #endregion current = (Stop)myStack.Pop(); continue; } var randStop = _rnd.Next(neighbors.Count()); var nextStop = neighbors[randStop]; InterConnectStops(current, nextStop); myStack.Push(current); current = nextStop; unvisitedStops.Remove(current); } #endregion //genarating mines location for (int i = 0; i < 4; i++) { MineLocations.Add(StopsList[_rnd.Next(StopsList.Count - 10 * i) + 10 * i]); } return(this); }