Exemplo n.º 1
0
        public bool TryExitFromElevator(IPerson person)
        {
            if (!Elevator.Contains(person))
            {
                return(false);
            }

            if (Elevator.State != ElevatorState.Opened)
            {
                return(false);
            }

            if (Elevator.CurrentFloor != Elevator.TargetFloor)
            {
                return(false);
            }

            if (person.CurrentFloor != person.TargetFloor)
            {
                return(false);
            }

            if (person.CurrentFloor != Elevator.CurrentFloor)
            {
                return(false);
            }

            Elevator.Drop(person);
            person.SetState(PersonState.Exited);
            PersonObservable.OnNext(new PersonAction(person, GetFloor(person.CurrentFloor),
                                                     PersonActionType.ExitedElevator));
            return(true);
        }
Exemplo n.º 2
0
        public bool TryEnterOnFloorToWaitElevator(IPerson person, IFloor floor)
        {
            if (floor.IsFull)
            {
                return(false);
            }

            if (person.State != PersonState.Unknown)
            {
                return(false);
            }

            if (floor.TryAttachToFloor(person))
            {
                person.SetState(PersonState.WaitElevator);
                person.SetFloor(floor.FloorNumber);
                PersonObservable.OnNext(new PersonAction(person, floor, PersonActionType.WaitingForElevator));
                return(true);
            }

            return(false);
        }