Example #1
0
 public bool AddTrip(TransitFlight trip)
 {
     if (TripsCount >= MaxTrips - trip.tripsInfo.Count)
     {
         return(false);
     }
     if (this == trip.From)
     {
         Outgoing.Add(trip);
     }
     else if (this == trip.To)
     {
         Incoming.Add(trip);
     }
     return(true);
 }
Example #2
0
        private void generateTimer_Tick(object sender, EventArgs e)
        {
            Trip trip;

            if ((Timer)sender == generateTimerSea)
            {
                trip = new SeaTrip(SeaPorts);
            }
            else
            {
                if (rand.Next(0, 2) == 0) // transit or direct
                {
                    trip = new DirectFlight(Airports);
                }
                else
                {
                    trip = new TransitFlight(Airports);
                }
            }
            bool valid = trip.From.AddTrip(trip) && trip.To.AddTrip(trip);

            // valid if both airports capacity is not reached yet
            if (valid)
            {
                trip.Visible = true;
                if ((Timer)sender == generateTimerSea)
                {
                    SeaTrips.Add(trip);
                }
                else
                {
                    Flights.Add(trip);
                }
                updateInfo(selected);
            }
            else
            {
                trip.Delete();
            }
        }