Пример #1
0
 /// <summary>
 ///     Creates elevator instance
 /// </summary>
 /// <param name="logger">Logger for output debug info</param>
 public Elevator(ILogger <Elevator> logger)
 {
     _logger = logger;
     _elevatorStateObservable  = new Subject <IElevatorState>();
     _elevatorActionObservable = new Subject <ElevatorAction>();
     _elevatorState            = ElevatorStateFactory.CreateNone(_elevatorStateObservable);
     CurrentFloor = TargetFloor = 0;
 }
Пример #2
0
 private void OnElevatorStateReadyToChange(IElevatorState state)
 {
     if (state.State == ElevatorState.Opened)
     {
         OnElevatorIsTryingToMove();
     }
     else if (state.State == ElevatorState.Moving)
     {
         OnElevatorIsOpening();
     }
 }
Пример #3
0
        /// <summary>
        ///     Set the new state on elevator
        /// </summary>
        /// <param name="newState">New state</param>
        /// <param name="force">
        ///     Normally we don't allow enter the same state two times, but this flag force enter the same state
        ///     again
        /// </param>
        // ReSharper disable once FlagArgument
        private void SetState(IElevatorState newState, bool force = false)
        {
            if (_elevatorState.State == newState.State && !force)
            {
                return;
            }
            var previousState = _elevatorState;

            _elevatorState = newState;
            UpdateElevatorActions(previousState, newState);
        }
Пример #4
0
    public void BuildElevator()
    {
        int floorsNumber = 2;

        if (floorsNumberInput.text != "")
        {
            floorsNumber = System.Convert.ToInt32(floorsNumberInput.text);
        }
        if (floorsNumber < 2)
        {
            floorsNumber = 2;
        }
        if (floorsNumber > 100)
        {
            floorsNumber = 100;
        }

        MaximumFloor = floorsNumber;
        CurrentFloor = 1;
        Interfloor   = 1f;
        currentState = new WaitOnFloor();

        GameObject floorButtonPrefab = (GameObject)Resources.Load("floorButton");
        GameObject floorPrefab       = (GameObject)Resources.Load("Floor");


        for (int i = 1; i <= floorsNumber; i++)
        {
            GameObject  floorButtonObj = Instantiate(floorButtonPrefab, elevatorPanelButtonsTransform);
            FloorButton floorButton    = floorButtonObj.GetComponent <FloorButton> ();
            floorButton.SetFloor(i);
            floorButton.IsActive = false;

            GameObject floorObj = Instantiate(floorPrefab, floorsTransform);
            Floor      floor    = floorObj.GetComponent <Floor> ();
            onFloorChanged += floor.SetCurrentElevatorFloorNumber;
            floor.SetFloor(floorsNumber + 1 - i);
            floor.SetCurrentElevatorFloorNumber(CurrentFloor);

            floors.Add(floor.FloorNumber, floor);
        }
        elevatorPanelUpdater.UpdateRect();
        floorsUpdater.UpdateRect();



        startPage.SetActive(false);
    }
Пример #5
0
        private void UpdateElevatorActions(IElevatorState previousState, IElevatorState newState)
        {
            switch (newState.State)
            {
            case ElevatorState.Moving when previousState.State != ElevatorState.Moving:
                _elevatorActionObservable.OnNext(new ElevatorAction(ElevatorActionType.StartMoving));
                break;

            case ElevatorState.Opened when previousState.State == ElevatorState.Moving:
                _elevatorActionObservable.OnNext(new ElevatorAction(ElevatorActionType.EndMoving));
                _elevatorActionObservable.OnNext(new ElevatorAction(ElevatorActionType.Opening));
                break;

            case ElevatorState.None:
                break;

            default:
                _elevatorActionObservable.OnNext(new ElevatorAction(ElevatorActionType.RetryOpening));
                break;
            }
        }
Пример #6
0
 public Elevator()
 {
     this.CurrentElevatorState = CloseState;
 }
Пример #7
0
 public Elevator(IElevatorState elevatorState)
 {
     ElevatorState = elevatorState;
 }
Пример #8
0
 public void ChangeState(IElevatorState newState)
 {
     currentState = newState;
 }