Пример #1
0
    /*---------------------------------------------------------
    * Method: getAiports
    *
    * Purpose: Generates the list of airports needed by passengers
    *
    * Returns: List of relevant Airport objects
    *--------------------------------------------------------*/
    static public List <Airport> getAirports(List <Passenger> people, List <Airport> airports)
    {
        foreach (Passenger p in people)
        {
            bool depart = false;
            bool arrive = false;

            /*----------------------------------
             * First check to see if the
             * airport has already been found.
             * -----------------------------------*/
            foreach (Airport port in airports)
            {
                if (p.origin.city == port.position.city && p.origin.state == port.position.state)
                {
                    port.departing.Add(p);
                    depart = true;
                }
                if (p.destination.city == port.position.city && p.destination.state == port.position.state)
                {
                    port.arriving.Add(p);
                    arrive = true;
                }
            }

            /*----------------------------------
             * If it was not found,
             * find it and add to list.
             * -----------------------------------*/
            if (!depart)
            {
                Airport a = Geolocator.findNearestAirport(p.origin);
                a.departing.Add(p);
                airports.Add(a);
            }
            if (!arrive)
            {
                Airport a = Geolocator.findNearestAirport(p.destination);
                a.arriving.Add(p);
                airports.Add(a);
            }
        }
        return(airports);
    }