Esempio n. 1
0
        /// <summary>
        /// Gets the next floor the lift will move to.
        /// </summary>
        private int NextFloor()
        {
            if (CurrentFloor == (MaxFloors - 1))
            {
                return(CurrentFloor - 1);
            }

            if (CurrentFloor == 0)
            {
                return(CurrentFloor + 1);
            }

            if (!IsEmpty())
            {
                int?floorToMoveTo = null;

                var mechanics         = Passengers.Where(p => p.IsMechanic).ToList();
                var regularPassengers = Passengers.Where(p => !p.IsMechanic).ToList();

                if (mechanics.Any())
                {
                    floorToMoveTo = CalculateNextFloorLiftNotEmpty(mechanics);
                }
                else
                {
                    floorToMoveTo = CalculateNextFloorLiftNotEmpty(regularPassengers);
                }

                if (floorToMoveTo != null)
                {
                    return(floorToMoveTo.Value);
                }
            }
            else if (HasFloorsWithWaitingMechanics())
            {
                if (PreviousFloor > CurrentFloor)
                {
                    return(Floors.GetMinFloorWaitingMechanic());
                }
                else if (CurrentFloor > PreviousFloor)
                {
                    return(Floors.GetMaxFloorWaitingMechanic());
                }
            }
            else
            {
                if (PreviousFloor > CurrentFloor)
                {
                    return(Floors.GetMinFloorWaitingPerson());
                }
                else if (CurrentFloor > PreviousFloor)
                {
                    return(Floors.GetMaxFloorWaitingPerson());
                }
            }

            return(0);
        }