public void OnPassRoom(Room room, Person person)
        {
            // Make sure the person has not called the elvator yet, and wants to call the elevator.
            if (!person.CalledElevator && person.CurrentRoom is ElevatorShaft && person.Path != null && person.Path.Count > 1 && person.Path.ElementAt(0) is ElevatorShaft)
            {
                // Get the start shaft (the shaft to begin the elevator trip).
                person.StartShaft = person.CurrentRoom as ElevatorShaft;

                // Set the end shaft to the start shaft(the shaft to end the elvator trip).
                person.TargetShaft = person.StartShaft;

                // Find the real end shaft.
                for (int i = 0; i < person.Path.Count; i++)
                {
                    if (!(person.Path.ElementAt(i) is ElevatorShaft))
                    {
                        break;
                    }
                    person.TargetShaft = person.Path.ElementAt(i) as ElevatorShaft;
                }

                ElevatorDirection dir = person.TargetShaft.RoomPosition.Y < person.StartShaft.RoomPosition.Y ? ElevatorDirection.Down : ElevatorDirection.Up;

                // If we have a target shaft that's not a start shaft, this person calls the elevator!
                if (person.TargetShaft != null && person.TargetShaft != person.StartShaft)
                {
                    // Call the elevator
                    person.CalledElevator = true;
                    (person.CurrentRoom as ElevatorShaft).CallElevator(dir);
                    (person.CurrentRoom as ElevatorShaft).ElevatorArrival += person.Person_ElevatorArrival;
                    person.CurrentTask = PersonTask.InQueue;
                }
            }
        }
示例#2
0
 private void Stop(int floor, Dictionary <int, bool> _floorReady, ref int _currentLevel)
 {
     _status            = ElevatorDirection.ELEVATOR_HOLD;
     _currentLevel      = floor;
     _floorReady[floor] = false;
     Console.WriteLine("Stopped at floor {0}", floor);
 }
示例#3
0
    public void MoveActor(GameObject actor, ElevatorDirection dir)
    {
        //Where the actor is
        var currentRoom       = actor.GetComponent <RoomDetector> ().currentRoom;
        int currentRoomIndex  = currentRoom.GetComponent <RoomController> ().index;
        int currentFloorIndex = currentRoom.transform.parent.GetComponent <FloorController> ().floorIndex;
        //Where its going
        int nextIndex = currentFloorIndex;

        if (dir == ElevatorDirection.Up)
        {
            nextIndex += 1;
        }
        else if (dir == ElevatorDirection.Down)
        {
            nextIndex -= 1;
        }
        //Making sure its in bounds
        if (nextIndex < 0 || nextIndex >= VaultController.instance.numberOfFloors)
        {
            return;
        }
        Debug.Log(string.Format("Moving: {0} {1} from {2} to {3} and position {4}",
                                actor.name, dir.ToString(), currentFloorIndex, nextIndex, currentRoomIndex));
        //Then move the actor
        GameObject targetRoom        = VaultController.instance.getRoomOnFloor(currentRoomIndex, nextIndex);
        Transform  targetDestination = targetRoom.GetComponent <RoomController> ().getElevatorTransformTarget();

        actor.transform.position = targetDestination.position;
    }
示例#4
0
 public void OnStartMoving()
 {
     movingDirection = GetDirectionToRequestedFloor(currRequest.FloorNum);
     DirectionChanged.Invoke(movingDirection);
     nextFloorNum = movingDirection == ElevatorDirection.up ? currFloorNum + 1 : currFloorNum - 1;
     nextFloorNum = Mathf.Clamp(nextFloorNum, 1, Floors.Count);
 }
示例#5
0
        private void Update()
        {
            if (_currentPower == _maxPower)
            {
                if (_direction == ElevatorDirection.Up)
                {
                    transform.position += (Vector3.up * _speed * Time.deltaTime);
                    if (transform.position.y > _highestStory.Y)
                    {
                        transform.position = _highestStory;
                    }

                    if (transform.position == _highestStory)
                    {
                        _direction = ElevatorDirection.Down;
                    }
                }
                else
                {
                    transform.position += (Vector3.down * _speed * Time.deltaTime);
                    if (transform.position.y < _lowestStory.Y)
                    {
                        transform.position = _lowestStory;
                    }

                    if (transform.position == _lowestStory)
                    {
                        _direction = ElevatorDirection.Up;
                    }
                }
            }
        }
        public string AddRequestToPipeline(Button button)
        {
            if (!ValidateRequest())
            {
                //Todo : logic to validate user service request considering current floor
                return("");
            }

            //var elevatorName = ElevatorController.Instance.elevatorRequestPipeline
            //                                                .AddRequestToPipeline(button.CurrentFloorNummber, button.DestinationFloorNumber);

            int requestorCurrentFloor     = button.CurrentFloorNummber;
            int requestedDestinationFloor = button.DestinationFloorNumber;

            ElevatorDirection direction = (requestorCurrentFloor - requestedDestinationFloor) > 0 ? ElevatorDirection.Downwards : ElevatorDirection.Upwards;

            var serviceRequest = new ElevatorServiceRequest()
            {
                ServiceRequestId        = Guid.NewGuid(),
                DeistinationFloor       = requestedDestinationFloor,
                SourceFloor             = requestorCurrentFloor,
                ServiceRequestDirection = direction
            };

            Console.WriteLine($"Request : {serviceRequest.SourceFloor} to : {serviceRequest.DeistinationFloor}, direction : {serviceRequest.ServiceRequestDirection}");

            this.ServiceRequestPipeLine.Add(serviceRequest.ServiceRequestId.ToString(), serviceRequest);

            //Update ElevatorController to process
            this.AllocateElevatorAndProcessRequest(direction);
            return("");
        }
 public void ClearReservations(int floorIndex, ElevatorDirection direction)
 {
     var reservationsToRemove = _reservations.Where(r => r.FloorIndex == floorIndex && (r.Direction == direction || r.Direction == ElevatorDirection.None)).ToList();
     foreach (var reservationToRemove in reservationsToRemove)
     {
         _reservations.RemoveAll(r => r.Equals(reservationToRemove));
         OnReservationRemoved(new ItemEventArgs<IReservation>(reservationToRemove));
     }
 }
 public ElevatorTileBehaviour(Tile tile, KeyValuePairs kvp) : base(tile, kvp)
 {
     Distance      = kvp.GetInteger("distance", 1);
     Speed         = 1.0f / Robot.Robot.STEP_TIME;
     Direction     = kvp.GetEnum("direction", ElevatorDirection.Up);
     Trigger       = kvp.GetEnum("trigger", ElevatorTrigger.Powered);
     RiseSoundPath = kvp.GetString("rise_sound", null);
     FallSoundPath = kvp.GetString("fall_sound", null);
 }
        private void SetDirection(ElevatorDirection direction)
        {
            var isGoingUp = direction == ElevatorDirection.Up;
            var targetPos = isGoingUp ? _endLocalPos : _startLocalPos;

            _elevator.SetValue("_goingToTheEnd", isGoingUp);
            _elevator.SetValue("_targetLocalPos", targetPos);
            _interactVolume.transform.Rotate(0f, 180f, 0f);
        }
 public void PlaceReservation(int floorIndex, ElevatorDirection direction)
 {
     bool reservationExists = _reservations.Exists(r => r.Direction == direction && r.FloorIndex == floorIndex);
     if (!reservationExists)
     {
         var newReservation = new Reservation { Direction = direction, FloorIndex = floorIndex };
         _reservations.Add(newReservation);
         OnReservationPlaced(new ItemEventArgs<IReservation>(newReservation));
     }
 }
 public ButtonPanel BuildButtonPanel(ElevatorDirection direction, IButtonCreator buttonCreator, IElevatorController elevatorController, IReservationSystem reservationSystem)
 {
     var newButtonPanel = new ButtonPanel
     {
         Direction = direction
     };
     newButtonPanel.CreateButtons(buttonCreator, elevatorController.Floors);
     newButtonPanel.SetButtonEvents(reservationSystem, elevatorController);
     return newButtonPanel;
 }
示例#12
0
 /// <summary>
 ///  Constructs an elevator centered on the given x and y with the
 ///  given velocity
 /// </summary>
 /// <param name="contentManager">the content manager for loading content</param>
 /// <param name="spriteName">the name of the sprite for the teddy bear</param>
 /// <param name="x">the x location of the center of the teddy bear</param>
 /// <param name="y">the y location of the center of the teddy bear</param>
 /// <param name="id">the identifing number or the elevator</param>
 public Elevator(ContentManager contentManager,
                 int id,
                 int x, int y)
 {
     this.elevatorDirection = ElevatorDirection.Stop;
     this.id = id;
     LoadContent(contentManager,
                 @"Graphics\Elevator",
                 @"Graphics\State\Stop",
                 (@"Graphics\Number\" + (char)('0' + floorNum / 10)) + (char)('0' + floorNum % 10),
                 x, y);
 }
示例#13
0
    public void AddRequest(int desiredFloorNum, ElevatorDirection desiredDirection, ElevatorController elevator)
    {
        var request         = new ElevatorController.Request(desiredDirection, desiredFloorNum);
        var closestElevator = GetClosestElevator(request, elevator);

        if (closestElevator == null)
        {
            return;
        }

        closestElevator.AddRequest(desiredFloorNum, desiredDirection);
    }
示例#14
0
        internal void AddNewServiceRequest(int floorNumber, ElevatorDirection elevatorDirection)
        {
            switch (elevatorDirection)
            {
            case ElevatorDirection.Upwards:
                AddServiceRequestInUpwardList(floorNumber);
                break;

            case ElevatorDirection.Downwards:
                AddServiceRequestInDownwardList(floorNumber);
                break;
            }
        }
示例#15
0
        private async Task Move(Elevator elevator, ElevatorDirection elevatorDirection, int numberOfFloorsToMove)
        {
            var floor = elevator.CurrentFloor;

            for (var i = 0; i < numberOfFloorsToMove; i++)
            {
                Thread.Sleep(ElevatorOperationTimeInMiSec);

                floor = elevatorDirection == ElevatorDirection.Up ? floor + 1 : floor - 1;
                elevator.CurrentFloor = floor;
                await SaveLog(elevator, ElevatorAction.Move);
            }
        }
 public bool ReservationExistsBeyond(int floorIndex, ElevatorDirection direction)
 {
     switch (direction)
     {
         case ElevatorDirection.Up:
             return _reservations.Exists(r => r.FloorIndex > floorIndex);
         case ElevatorDirection.Down:
             return _reservations.Exists(r => r.FloorIndex < floorIndex);
         default:
             throw new ArgumentException("Direction must be ElevatorDirection.Up or ElevatorDirection.Down", nameof(direction));
     }
     
 }
示例#17
0
    private int GetNextAim()
    {
        if (!HasCalls)
        {
            if (PeoplesInside == 0)
            {
                __elevatorDirection = ElevatorDirection.Down;
                return(0);
            }
            else
            {
                return(CurrentFloor);
            }
        }

        List <int> avaliableFloors = new List <int>();

        for (int i = 0; i < Floors; i++)
        {
            bool stopedfromOutside = (_floorStates[i].DownPressed && __elevatorDirection == ElevatorDirection.Down) || (_floorStates[i].UpPresed && __elevatorDirection == ElevatorDirection.Up);
            bool stopedFromInside  = _floorStates[i].ChoosedInElevator && ((i < _currentPosition && __elevatorDirection == ElevatorDirection.Down) || (i > _currentPosition && __elevatorDirection == ElevatorDirection.Up));

            if (stopedFromInside || stopedfromOutside)
            {
                avaliableFloors.Add(i);
            }
        }

        if (avaliableFloors.Count == 0)
        {
            if (HasCalls)
            {
                if (__elevatorDirection == ElevatorDirection.Down)
                {
                    __elevatorDirection = ElevatorDirection.Up;
                    return(GetNextAim());
                }
                if (__elevatorDirection == ElevatorDirection.Up)
                {
                    __elevatorDirection = ElevatorDirection.Down;
                    return(GetNextAim());
                }
            }
        }
        else
        {
            return(avaliableFloors.OrderBy(f => Mathf.Abs(f - CurrentFloor)).First());
        }
        return(0);
    }
        private async void AllocateElevatorAndProcessRequest(ElevatorDirection direction)
        {
            string elevatorName = string.Empty;

            elevatorName = ElevatorController.Instance.AllocateElevator(direction);

            //ToDo - can we run async without waiting
            //button.DisplayDetails()

            //Call this async without waiting for elevatormovement
            Task.Run(() => ElevatorController.Instance.ProcessRequest(direction));

            //return elevatorName;
        }
        public string AllocateElevator(ElevatorDirection elevatorDirection)
        {
            var unAllottedServiceRequest = ElevatorController.Instance.ElevatorRequestPipeline
                                           .ServiceRequestPipeLine
                                           .Where(sr => string.IsNullOrEmpty(sr.Value.ElevatorName) == true);

            string elevatorName = string.Empty;

            foreach (var srequest in unAllottedServiceRequest)
            {
                elevatorName = AssignElevatorCar(elevatorDirection, srequest);
            }

            return(elevatorName);
        }
 public void MoveFloorByOne(ElevatorDirection direction)
 {
     switch (direction)
     {
         case ElevatorDirection.Up:
             CurrentFloorIndex++;
             break;
         case ElevatorDirection.Down:
             CurrentFloorIndex--;
             break;
         default:
             throw new ArgumentException("Direction must be ElevatorDirection.Up or ElevatorDirection.Down", nameof(direction));
     }
     Thread.Sleep(1000); //Simulate going up one floor
 }
示例#21
0
        /// <summary>
        /// Call the elevator to do something.
        /// </summary>
        /// <param name="floor">The floor from which the call comes.</param>
        /// <param name="direction">The direction the elevator needs to travel.</param>
        public void CallElevator(int floor, ElevatorDirection direction)
        {
            // if the floor is already added to the queue, add the new direction to it.
            if (_queue.ContainsKey(floor))
            {
                _queue[floor] |= direction;
            }
            // else add the floor.
            else
            {
                _queue.Add(floor, direction);
            }

            _targetFloor = GetTargetFloor();
        }
示例#22
0
        public void Ascend(int floor, int _upperLevel, Dictionary <int, bool> _floorReady, ref int _currentLevel)
        {
            for (int i = _currentLevel + 1; i <= _upperLevel; i++)
            {
                if (_floorReady[i])
                {
                    Stop(floor, _floorReady, ref _currentLevel);
                    break;
                }
                Console.WriteLine("Going Up - Floor {0}",
                                  i);
            }

            _status = ElevatorDirection.ELEVATOR_HOLD;
            Console.WriteLine("Waiting..");
        }
示例#23
0
        public void ResetElevatorCar()
        {
            if (ElevatorDirection == ElevatorDirection.Upwards)
            {
                ServiceRequestListUpwards = null;
            }
            if (ElevatorDirection == ElevatorDirection.Downwards)
            {
                ServiceRequestListDownwards = null;
            }

            this.CurrentFloor      = 0;
            this.Status            = ElevatorCarStatus.Idle;
            this.ElevatorDirection = ElevatorDirection.None;
            Console.WriteLine($"All service request of Elevator : {this.Name} completed, status : {this.Status}!");
        }
示例#24
0
        public void CallElevatorRequest(ElevatorDirection direction, int floor)
        {
            switch (direction)
            {
            case ElevatorDirection.Down:
                _downOperations.Add(floor);
                _downOperations.Sort();
                _downOperations.Reverse();
                break;

            case ElevatorDirection.Up:
                _upOperations.Add(floor);
                _upOperations.Sort();
                break;
            }
        }
示例#25
0
        /// <summary>
        ///
        ///
        ///
        /// Alogrithm => To Set Elevator car movement
        ///     Check if Car is already moving
        ///         If No
        ///             Then read the next immediate destination floor
        ///             Begin Move
        ///         Else If Yes (car busy)
        ///             Then verify if next immediate destination is to be updated??
        /// </summary>
        public void ProcessRequestWorker()
        {
            //setup elevator direction
            if (ElevatorController.Instance.ElevatorRequestPipeline.ServiceRequestPipeLine.Any(sr => sr.Value.ElevatorName.Equals(this.Name)))
            {
                var direction = ElevatorController.Instance.ElevatorRequestPipeline
                                .ServiceRequestPipeLine
                                .Values
                                .FirstOrDefault(sr => sr.ElevatorName.Equals(this.Name))
                                .ServiceRequestDirection;

                this.ElevatorDirection = direction;
                ProcessWorkerByDirection(direction);

                this.ElevatorDirection = direction == ElevatorDirection.Upwards ? ElevatorDirection.Downwards : ElevatorDirection.Upwards;
                ProcessWorkerByDirection(direction);
            }
        }
示例#26
0
        public Elevator(int line)
        {
            State     = ElevatorState.CloseWaiting;
            Direction = ElevatorDirection.None;
            elevator  = new Rectangle()
            {
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Margin  = new Thickness(10 + line * 50, 10 + (20 - 1) * 40, 0, 0),
                Width   = 24,
                Height  = 36,
                Fill    = new SolidColorBrush(Color.FromRgb(200, 200, 0)),
                Opacity = 0.5
            };
            Line  = line;
            Floor = 1;
            Thread thread = new Thread(Scheduling);

            thread.Start();
        }
示例#27
0
        public async Task <string> ProcessRequest(ElevatorDirection elevatorDirection)
        {
            //Todo -- Re-think on the algorithm to process the requests??

            //ToDo -- why did we added this line multiple time
            //this.elevatorAllocationStrategy.AllocateElevator(elevatorDirection);

            Task <int> result = Task.Run(() => ProcessTriggerElevatorAction());

            //do
            //{
            //    string x = await ProcessTriggerElevatorAction();
            //} while (Instance.ElevatorRequestPipeline.ServiceRequestPipeLine.Any()
            //            && Instance.ElevatorRequestPipeline.ServiceRequestPipeLine.Count > 0);
            //do
            //{
            //    ProcessTriggerElevatorAction();
            //} while (Instance.ElevatorRequestPipeline.ServiceRequestPipeLine.Any());
            //ProcessTriggerElevatorAction();

            return(string.Empty);
        }
示例#28
0
        private void ProcessWorkerByDirection(ElevatorDirection direction)
        {
            bool IsPendingServiceRequest = false;
            int  _destinationFloor;

            IsPendingServiceRequest = GetNextDestinationFloorToService(out _destinationFloor) ? true : false;

            //Step #1.1.3 => Begin working
            //Step #1.2.3 => Begin working
            while ((this.Status == ElevatorCarStatus.Idle || this.ServiceRequestList.Any()) && IsPendingServiceRequest)
            {
                this.DestinationFloor = _destinationFloor;

                ProcessRequestCurrent();

                IsPendingServiceRequest = GetNextDestinationFloorToService(out _destinationFloor) ? true : false;
            }
            if (!this.ServiceRequestList.Any() || this.ServiceRequestList.Count == 0)
            {
                ResetElevatorCar();
            }
        }
        private string AssignElevatorCar(ElevatorDirection elevatorDirection, KeyValuePair <string, ElevatorServiceRequest> srequest)
        {
            var serviceRequest = srequest.Value;

            bool IsUpwards   = elevatorDirection == ElevatorDirection.Upwards ? true : false;
            var  elevatorCar = ElevatorController.Instance
                               .ElevatorCarList
                               .Where(e => e.ElevatorDirection.Equals(serviceRequest.ServiceRequestDirection))
                               .OrderBy(e => e.ServiceRequestList.Count)
                               .Take(1)
                               .FirstOrDefault() as ElevatorCar;

            if (elevatorCar == null)
            {
                elevatorCar = ElevatorController.Instance
                              .ElevatorCarList
                              .Where(e => e.Status.Equals(ElevatorCarStatus.Idle) ||
                                     e.ElevatorDirection.Equals(serviceRequest.ServiceRequestDirection))
                              .OrderBy(e => e.ServiceRequestList.Count)
                              .Take(1)
                              .FirstOrDefault() as ElevatorCar;
            }

            ElevatorController.Instance.ElevatorRequestPipeline
            .ServiceRequestPipeLine[srequest.Key.ToString()].ElevatorName = elevatorCar.Name;
            //Updating Elevator Direction as per ServiceRequest direction
            if (ElevatorController.Instance.ElevatorCarList.Any(e => e.Name.Equals(elevatorCar.Name)))
            {
                ElevatorController.Instance.ElevatorCarList.First(e => e.Name.Equals(elevatorCar.Name)).ElevatorDirection = srequest.Value.ServiceRequestDirection;

                ElevatorController.Instance.ElevatorCarList.First(e => e.Name.Equals(elevatorCar.Name)).AddNewServiceRequest(srequest.Value.SourceFloor, srequest.Value.ServiceRequestDirection);
                ElevatorController.Instance.ElevatorCarList.First(e => e.Name.Equals(elevatorCar.Name)).AddNewServiceRequest(srequest.Value.DeistinationFloor, srequest.Value.ServiceRequestDirection);
            }

            return(elevatorCar.Name);
        }
 public bool ReservationExistsAt(int floorIndex, ElevatorDirection direction)
 {
     return _reservations.Exists(r => r.FloorIndex == floorIndex && (r.Direction == direction || r.Direction == ElevatorDirection.None));
 }
示例#31
0
        //todo: make it not that scary
        public void AddRequest(int desiredFloorNum, ElevatorDirection desiredDirection)
        {
            if (desiredFloorNum < 1 || !Floors.ContainsKey(desiredFloorNum))
            {
                return;
            }

            if (desiredDirection == ElevatorDirection.none) // from cabin btn
            {
                if (desiredFloorNum == currFloorNum)
                {
                    return;
                }

                desiredDirection = GetDirectionToRequestedFloor(desiredFloorNum);
                CabinFloorRequested.Invoke(desiredFloorNum);
            }

            var request = new Request(desiredDirection, desiredFloorNum);

            if (IsIdle)
            {
                if (request.Direction == ElevatorDirection.up)
                {
                    currRequests         = upRequests;
                    currOppositeRequests = downRequests;
                    currDelayedRequests  = upDelayedRequests;
                }
                else
                {
                    currRequests         = downRequests;
                    currOppositeRequests = upRequests;
                    currDelayedRequests  = downDelayedRequests;
                }

                currRequests.Enqueue(request);
                currRequest = request;
                SetState(movingState);
                PrintElevatorState();
                return;
            }

            if (request.Equals(currRequest))
            {
                RequestNoLongerActual.Invoke(currRequest, this);
            }
            else if (request.Direction != currRequest.Direction)
            {
                currOppositeRequests.Enqueue(request);
            }
            else if (movingDirection != request.Direction)
            {
                currRequests.Enqueue(request);
            }
            else if ((movingDirection == ElevatorDirection.up ? 1 : -1) * (request.FloorNum - currFloorNum) > 0)
            {
                currRequests.Enqueue(request);
            }
            else
            {
                currDelayedRequests.Enqueue(request);
            }

            if (IsIdle)
            {
                return;
            }

            if (currentState != doorsCycleState)
            {
                currRequest = currRequests.Peek;
            }

            PrintElevatorState();
        }
示例#32
0
 public string AllocateElevator(ElevatorDirection direction)
 {
     return(this.elevatorAllocationStrategy.AllocateElevator(direction));
 }
示例#33
0
        void Scheduling()
        {
            while (true)
            {
                if (Job.JobNum() == 0 || (Job.JobNum() == 1 && (Job.Up[Floor] != 0 || Job.Down[Floor] != 0 || Job.Inside[Floor] != 0)))
                {
                    Direction = ElevatorDirection.None;
                }
                switch (State)
                {
                case ElevatorState.CloseWaiting:
                {
                    if (Job.JobNum() != 0 && Timeout >= 10)
                    {
                        if (Direction == ElevatorDirection.None)
                        {
                            if (JobDirection() == 1000)
                            {
                                State         = ElevatorState.OpenWaiting;
                                Job.Up[Floor] = 0;
                                continue;
                            }
                            if (JobDirection() == -1000)
                            {
                                State           = ElevatorState.OpenWaiting;
                                Job.Down[Floor] = 0;
                                continue;
                            }
                            if (JobDirection() > 0)
                            {
                                Direction = ElevatorDirection.Up;
                            }
                            if (JobDirection() < 0)
                            {
                                Direction = ElevatorDirection.Down;
                            }
                        }
                        if (Direction == ElevatorDirection.Up)
                        {
                            Job.Up[Floor] = 0;
                        }
                        if (Direction == ElevatorDirection.Down)
                        {
                            Job.Down[Floor] = 0;
                        }
                        State   = ElevatorState.Moving;
                        Timeout = 0;
                    }
                    else
                    {
                        Thread.Sleep(100);
                        Timeout++;
                    }
                    break;
                }

                case ElevatorState.OpenWaiting:
                {
                    if (Timeout >= 20)
                    {
                        State   = ElevatorState.CloseWaiting;
                        Timeout = 0;
                    }
                    else
                    {
                        Thread.Sleep(100);
                        Timeout++;
                    }
                    break;
                }

                case ElevatorState.Moving:
                {
                    if (Direction == ElevatorDirection.Up)
                    {
                        if (Floor == 20)
                        {
                            State     = ElevatorState.Stopping;
                            Direction = ElevatorDirection.Down;
                            continue;
                        }
                        if (Floor != 19)
                        {
                            if (Job.JobNum(Floor + 1) != 0)
                            {
                                State = ElevatorState.Stopping;
                            }
                        }
                        MoveUp();
                    }
                    if (Direction == ElevatorDirection.Down)
                    {
                        if (Floor == 1)
                        {
                            State     = ElevatorState.Stopping;
                            Direction = ElevatorDirection.Up;
                            continue;
                        }
                        if (Floor != 2)
                        {
                            if (Job.JobNum(Floor - 1) != 0)
                            {
                                State = ElevatorState.Stopping;
                            }
                        }
                        MoveDown();
                    }
                    break;
                }

                case ElevatorState.Stopping:
                {
                    State = ElevatorState.OpenWaiting;
                    break;
                }

                case ElevatorState.SOS:
                {
                    Thread.Sleep(10000);
                    break;
                }
                }
            }
        }
示例#34
0
 public Request(ElevatorDirection direction, int floorNum)
 {
     Direction = direction;
     FloorNum  = floorNum;
 }
        /// <summary>
        /// Moves the Elevator based on it's own data.
        /// </summary>
        public void Move()
        {
            #region IDLE
            //If the Direction is IDLE, and there is data inside the UP and DOWN List
            //Then the Elevator needs to change it's Direction depending on what List is bigger (more requests = more important).
            if (Direction == ElevatorDirection.IDLE)
            {
                if (Up.Count > Down.Count)
                {
                    Direction = ElevatorDirection.UP;
                }
                else
                {
                    Direction = ElevatorDirection.DOWN;
                }
            }
            #endregion

            if (Up.Count != 0 || Down.Count != 0)
            {
                #region UP
                if (Direction == ElevatorDirection.UP)
                {
                    //Changes Direction if the UP List is empty, but the DOWN List isn't
                    if (Up.Count == 0 && Down.Count != 0)
                    {
                        Direction = ElevatorDirection.DOWN;
                        Move();
                    }
                    else
                    {
                        //Goes one Y position up
                        PositionY++;
                        for (int i = 0; i < Up.Count; i++)
                        {
                            if (Up[i] == PositionY)
                            {
                                Up.RemoveAt(i);
                                break;
                            }
                        }
                    }
                }
                #endregion
                #region DOWN
                else if (Direction == ElevatorDirection.DOWN)
                {
                    //Changes Direction if the DOWN List is empty, but the UP List isn't
                    if (Up.Count != 0 && Down.Count == 0)
                    {
                        Direction = ElevatorDirection.UP;
                        Move();
                    }
                    else
                    {
                        //Goes one Y position down
                        PositionY--;
                        for (int i = 0; i < Down.Count; i++)
                        {
                            if (Down[i] == PositionY)
                            {
                                Down.RemoveAt(i);
                                break;
                            }
                        }
                    }
                }
                #endregion

                //Moves all the IHuman's that are in the Elevator and updates all their position to the Elevator's
                foreach (IHuman human in InElevator)
                {
                    human.PositionX = PositionX;
                    human.PositionY = PositionY;
                }
            }

            //Sets itself to IDLE if the the UP- and DOWN.Count are 0 (meaning the Elevator has nothing to do)
            if (Up.Count == 0 && Down.Count == 0)
            {
                Direction = ElevatorDirection.IDLE;
            }
        }
示例#36
0
 public void Click(ElevatorDirection direction, int floor)
 {
 }