예제 #1
0
 public void PassengerPressesButton(Skyscraper skyScraper, Passenger passenger)
 {
     if (passenger.DestinationFloor > FloorNum)
     {
         OnUpButtonPressed(skyScraper.Elevators);
     }
     else if (passenger.DestinationFloor < FloorNum)
     {
         OnDownButtonPressed(skyScraper.Elevators);
     }
     else
     {
     }
 }
예제 #2
0
 public void Update(Skyscraper skyscraper)
 {
     if (destinationQueue.Count > 0)
     {
         if (destinationQueue.Peek() > CurrentFloor)
         {
             if (Velocity < 20)
             {
                 Velocity = Velocity + (Accelaration / 1000);
             }
             HeightAboveCurrentFloor = HeightAboveCurrentFloor + (decimal)Velocity / 1000;
             if (HeightAboveCurrentFloor > 3)
             {
                 HeightAboveCurrentFloor = 0;
                 CurrentFloor++;
             }
             //TODO: add accelaration/Deceleration
         }
         else if (destinationQueue.Peek() < CurrentFloor || HeightAboveCurrentFloor > 0)
         {
             if (Velocity < 20)
             {
                 Velocity = Velocity + (Accelaration / 1000);
             }
             HeightAboveCurrentFloor = HeightAboveCurrentFloor - (decimal)Velocity / 1000;
             if (HeightAboveCurrentFloor < 0)
             {
                 HeightAboveCurrentFloor = (decimal)2.9999999;
                 CurrentFloor--;
             }
         }
         else if (HeightAboveCurrentFloor == 0)
         {
             //Arrived at destination
             Velocity = 0;
             destinationQueue.Dequeue();
             UnloadPassengers();         //TODO: Need to stop elevator for an amount of time whilst people exit
             LoadPassengers(skyscraper); //TODO: Need to stop elevator for an amount of time whilst people Enter
         }
     }
     else
     {
         LoadPassengers(skyscraper);
     }
 }
예제 #3
0
        private void LoadPassengers(Skyscraper skyscraper)
        {
            Floor currentFloor = skyscraper.Floors.Single(f => f.FloorNum == CurrentFloor);

            foreach (Passenger passenger in currentFloor.PassengersWaiting)
            {
                if (Passengers.Count == MaxPassengerCount)
                {
                    break;
                }
                Passengers.Add(passenger);
                passenger.InElevator = true;

                OnFloorButtonPressed(passenger.DestinationFloor);
            }
            currentFloor.DownButtonActive = false;
            currentFloor.UpButtonActive   = false;
            currentFloor.PassengersWaiting.RemoveAll(r => r.InElevator);

            foreach (Passenger passenger in currentFloor.PassengersWaiting)
            {
                currentFloor.PassengerPressesButton(skyscraper, passenger);
            }
        }
예제 #4
0
        internal void PassengerArrives(Skyscraper skyScraper, Passenger passenger)
        {
            PassengersWaiting.Add(passenger);

            PassengerPressesButton(skyScraper, passenger);
        }