public FugitiveDistanceMessage ToFugitiveDistanceMessage() { // calculate distance and reply FugitiveDistanceMessage msg = new FugitiveDistanceMessage() { DistanceInM = DistanceToFugitive, TimeToReach = TimeToReachFugitive, FugitiveClientId = ClientId }; return(msg); }
void _messaging_FugutiveLocationRecieved(object sender, MessageEventArgs <FugitiveLocationMessage> e) { // add fugitive var fugitive = ViewModelLocator.TrackerViewModel.FugitiveCollection.FirstOrDefault(p => p.ClientId == e.Message.ClientId); if (fugitive != null) { // update fugitive.Position = new Xamarin.Forms.Maps.Position(e.Message.Latitide, e.Message.Longitude); } else { // add fugitive = new Fugitive() { ClientId = e.Message.ClientId, Username = e.Message.Username, Position = new Xamarin.Forms.Maps.Position(e.Message.Latitide, e.Message.Longitude), Colour = AssignColour() }; ViewModelLocator.TrackerViewModel.FugitiveCollection.Add(fugitive); } ViewModelLocator.TrackerViewModel.UpdateMapPins(); if (ViewModelLocator.TrackerViewModel.Position != null) { var fugitiveGeolocatorPosition = fugitive.Position.ToGeolocatorPosition(); var distanceInKM = ViewModelLocator.TrackerViewModel.Position.CalculateDistance(fugitiveGeolocatorPosition, GeolocatorUtils.DistanceUnits.Kilometers); fugitive.DistanceToFugitive = distanceInKM * 1000; fugitive.TimeToReachFugitive = TimeSpan.FromSeconds(fugitive.DistanceToFugitive / FIVE_METERS_PER_SECOND); if (fugitive.DistanceToFugitive > CAUGHT_DISTANCE) { FugitiveDistanceMessage msg = fugitive.ToFugitiveDistanceMessage(); ViewModelLocator.TrackerViewModel.Messaging.SendFugitiveDistance(msg); } else { fugitive.IsCaught = true; CaughtMessage msg = fugitive.ToCaughtMessage(); ViewModelLocator.TrackerViewModel.Messaging.SendCaughtMessage(msg); } CheckIfGameIsComplete(); } }