コード例 #1
0
ファイル: Tower.cs プロジェクト: henbarlevi/FlightControl
 private void MangePlanesInAirport(AirportDTO airport)
 {
     //telling planes in airport where to move:
     for (int i = 0; i < airport.Planes.Count; i++)
     {
         PlaneDTO plane = airport.Planes[i];
         //if plane landing
         if (StationsInfoService.IsAttendingToLand(plane.StationId))
         {
             plane.StationId++;
         }
         //if plane on track
         else if (StationsInfoService.IsOnTrack(plane.StationId))
         {
             if (plane.State == PlaneState.Landing)
             {
                 plane.StationId++;
             }
             else//departuring
             {
                 plane.StationId = StationsInfoService.InAir; //tell the plane departure to air
                 //and from the plansOnHold queue:
                 DeparturePlanesOnHold.Dequeue();
             }
         }
         //if attending to park
         else if (StationsInfoService.IsAttendingToPark(plane.StationId))
         {
             //if the parking slots are empty -tell the plane to move there:
             PlaneDTO firstParkingSlot  = airport.Planes.FirstOrDefault(u => u.StationId == StationsInfoService.Parking[0]);
             PlaneDTO secondParkingSlot = airport.Planes.FirstOrDefault(u => u.StationId == StationsInfoService.Parking[1]);
             if (firstParkingSlot == null)
             {
                 plane.StationId = StationsInfoService.Parking[0];
                 //raise event about the parked plane:
                 PlaneParked.Invoke(plane, EventArgs.Empty);
             }
             else if (secondParkingSlot == null)
             {
                 plane.StationId = StationsInfoService.Parking[1];
                 //raise event about the parked plane:
                 PlaneParked.Invoke(plane, EventArgs.Empty);
             }
         }
         else if (StationsInfoService.IsAttendingToDepart(plane.StationId))
         {
             plane.StationId = StationsInfoService.Track;
         }
     }
 }
コード例 #2
0
ファイル: Tower.cs プロジェクト: henbarlevi/FlightControl
 //getting  request from plane that want to arrival/departure
 public void AcceptPlaneRequest(PlaneDTO plane)
 {
     if (plane != null)
     {
         if (StationsInfoService.IsInAir(plane.StationId)) //if plane is in air
         {
             //means plane want to land:
             ArrivalPlanesOnHold.Enqueue(plane);
         }
         else if (StationsInfoService.IsParking(plane.StationId)) //if plane parking
         {
             //means plane want to departure:
             DeparturePlanesOnHold.Enqueue(plane);
         }
     }
 }
コード例 #3
0
ファイル: Tower.cs プロジェクト: henbarlevi/FlightControl
 private void ManagePlanesOnHold(AirportDTO airport)
 {
     //mangaing the planes that want to departure/arrival:
     //check if the airport field is clean for departure:
     if (AirportFieldValidator.IsClearForDeparturing(airport))
     {
         // if there is plane that want to departure:
         if (DeparturePlanesOnHold.Count != 0)
         {
             //tell the plane to departure:
             PlaneDTO plane            = DeparturePlanesOnHold.Peek();
             PlaneDTO departuringPlane = airport.Planes.Find(p => p.PlaneId == plane.PlaneId);
             departuringPlane.StationId = StationsInfoService.AttendToDepart;
             //raise event that plane is departuring:
             PlaneDeparturing.Invoke(departuringPlane, EventArgs.Empty);
         }
         else //if there isnt planes that want to depart, check if there is plane that want land
         {
             // if there is plane that want to land:
             if (ArrivalPlanesOnHold.Count != 0)
             {
                 //check if the field clear for landing:
                 if (AirportFieldValidator.IsClearForLanding(airport))
                 {
                     //if field clear tell the plane to land:
                     PlaneDTO plane = ArrivalPlanesOnHold.Dequeue();
                     plane.StationId = StationsInfoService.AttendingToLand.First();
                     //adding plane to airport :
                     airport.Planes.Add(plane);
                     //raise event that plane is arriving:
                     PlaneArriving.Invoke(plane, EventArgs.Empty);
                 }
             }
         }
     }
 }