Example #1
0
        public void Elevator_ElevatorTimerElapsed(object sender, ElapsedEventArgs e)
        {
            if (myBuilding.Fire == true)
            {
                //Update elevator's status
                elevatorTimer.Stop();
                SetElevatorStatus(ElevatorStatus.Idle);

                //Inform all passengers inside
                List <Passenger> PassengersInsideTheElevator = new List <Passenger>(listOfPeopleInside);
                foreach (Passenger SinglePassengerInsideTheElevator in PassengersInsideTheElevator)
                {
                    SinglePassengerInsideTheElevator.ElevatorReachedNextFloor();
                    Thread.Sleep(SinglePassengerInsideTheElevator.GetAnimationDelay() * 40); //to make sure all passengers will be visible when leaving the building
                }
                lock (locker)
                {
                    this.listOfFloorsToVisit.Clear();
                }
            }

            if (GetNextFloorToVisit() == null)
            {
                elevatorTimer.Stop();
                SetElevatorStatus(ElevatorStatus.Idle);
            }
            else
            {
                //ThreadPool.QueueUserWorkItem(delegate { this.PrepareElevatorToGoToNextFloorOnTheList(); });
                this.PrepareElevatorToGoToNextFloorOnTheList();
            }
        }
Example #2
0
        private void FinalizeGoingToNextFloorOnTheList()
        {
            //Reset appropriate lamp on current floor
            switch (this.elevatorDirection)
            {
            case Direction.Up:
                currentFloor.LampUp = false;
                break;

            case Direction.Down:
                currentFloor.LampDown = false;
                break;

            case Direction.None:
                currentFloor.LampUp   = false;
                currentFloor.LampDown = false;
                break;

            default:
                break;
            }

            //Open the door
            this.OpenTheDoor();

            //Update elevator's status
            SetElevatorStatus(ElevatorStatus.WaitingForPassengersToGetInAndGetOut);

            //Inform all passengers inside
            List <Passenger> PassengersInsideTheElevator = new List <Passenger>(listOfPeopleInside);

            foreach (Passenger SinglePassengerInsideTheElevator in PassengersInsideTheElevator)
            {
                SinglePassengerInsideTheElevator.ElevatorReachedNextFloor();
                Thread.Sleep(SinglePassengerInsideTheElevator.GetAnimationDelay() * 40); //to make sure all passengers will be visible when leaving the building
            }

            //Add this elevator to next floor's list
            currentFloor.AddRemoveElevatorToTheListOfElevatorsWaitingHere(this, true);

            //Rise an event on current floor to inform passengers, who await
            currentFloor.OnElevatorHasArrivedOrIsNoteFullAnymore(new ElevatorEventArgs(this));

            //Enable the timer
            this.elevatorTimer.Start();
        }