Exemple #1
0
        //Метод для перегонки самолёта из его текущего положения в другой город
        private decimal SendPlane(string planeID, string destinationID, uint?flightNum)
        {
            double  distance = CitiesInfo.GetRoute(planesAndCities[planeID].ID, destinationID).Distance;
            decimal minus    = (decimal)distance * fuelPrice;

            currentSavings -= minus;
            SavingsChanged?.Invoke(this, currentSavings);
            planesAndCities[planeID] = null;
            PlaneFlight ongoingFlight = new PlaneFlight
            {
                AssociatedFlightNum = flightNum,
                AssociatedPlaneID   = planeID,
                DestinationID       = destinationID,
                DistanceLeft        = distance
            };

            planesProgress.Add(ongoingFlight);
            return(minus);
        }
Exemple #2
0
        private void ProcessPlaneFlights()
        {
            int i = 0;

            while (i < planesProgress.Count)
            {
                PlaneFlight flight = planesProgress[i];
                flight.DistanceLeft -= planes[flight.AssociatedPlaneID].Speed / 60.0;
                planes[flight.AssociatedPlaneID].DeprecationDegree += randomizer.NextDouble() * 0.003;
                planesAndCities[flight.AssociatedPlaneID]           = CitiesInfo.cities[flight.DestinationID];
                FlightProgressChanged?.Invoke(this,
                                              new FlightProgressEventArgs
                {
                    AssociatedFlight = flight.AssociatedFlightNum, AssociatedPlaneID = flight.AssociatedPlaneID,
                    TimeLeft         = TimeSpan.FromHours(flight.DistanceLeft / planes[flight.AssociatedPlaneID].Speed)
                });
                if (flight.DistanceLeft <= 0)
                {
                    if (flight.AssociatedFlightNum.HasValue)
                    {
                        FinishContract(flight.AssociatedFlightNum.Value);
                    }
                    if (planes[planesProgress[i].AssociatedPlaneID].Own == Plane.Owns.Rented && planes[planesProgress[i].AssociatedPlaneID].MarketC.Days <= 0)
                    {
                        observablePlanes.Remove(planes[planesProgress[i].AssociatedPlaneID]);
                        // planes.Remove(planesProgress[i].AssociatedPlaneID);
                    }
                    planesProgress.RemoveAt(i);
                    planes[flight.AssociatedPlaneID].status = "";
                }
                else
                {
                    i++;
                }
            }
        }