예제 #1
0
        public void ExecuteCalls(List <Floor> ltFloor)
        {
            if (_isOpen)
            {
                _timer.Stop();
                _floorDoor.Close();
                _isOpen = false;
            }
            if (_callControl.HasAnyRequest())
            {
                _levelSensor = new LevelSensor();
                IObserver motorObserver = new Motor(_txtElevator);
                IObserver cabinObserver = new CabinDoor(_txtElevator);
                IObserver floorObserver = new FloorDoor(_txtElevator);
                _levelSensor.stateChange += new Notify(motorObserver.Notify);
                _levelSensor.stateChange += new Notify(cabinObserver.Notify);
                _levelSensor.stateChange += new Notify(floorObserver.Notify);

                Direction direction = _callControl.UpdateRequestAndDirection(_currentDirection, _elevatorCurrentFloor);
                if (_currentDirection != direction)
                {
                    _currentDirection = direction;
                    UpdateCurrentHeight(ltFloor);
                }
                if (_currentDirection == Direction.up)
                {
                    _currentHeight = _motor.MotorUp(_currentHeight);
                }
                if (_currentDirection == Direction.down)
                {
                    _currentHeight = _motor.MotorDown(_currentHeight);
                }
                if (_cabinSensor.IsOnTheNextFloor(ltFloor, _elevatorCurrentFloor, _currentHeight, _currentDirection))
                {
                    UpdateCurrentFloor();
                    UpdateCurrentHeight(ltFloor);
                    _floorDisplay.ShowFloor(_elevatorCurrentFloor);
                    _cabinDisplay.ShowFloor(_elevatorCurrentFloor);
                    _cabinPanel.TurnOffCabinButtonForFloor(_elevatorCurrentFloor.ToString());
                    _isOpen = _callControl.FloorMakeCall(_elevatorCurrentFloor, _currentDirection, _levelSensor);
                }
            }
        }