Exemple #1
0
        private void Stand()
        {
            Status = "Stand";
            UpdateStatus?.Invoke(Status);
            Thread.Sleep(2500);
            ElevatorList.RemoveAt(0);

            FloorsInTheDirection = FloorsInTheDirection == 1 ? ElevatorList.Count : FloorsInTheDirection - 1;

            EventUpdateElevatorList?.Invoke(String.Join(" ", ElevatorList));
            OpenDoors();
        }
Exemple #2
0
        public void UpdateElevatorList(int floor, string status)
        {
            bool flag = false;

            if (!ElevatorList.Any())
            {
                ElevatorList.Add(floor);
                FloorsInTheDirection++;
                // AddFloorList?.Invoke(floor);
                EventUpdateElevatorList?.Invoke(String.Join(" ", ElevatorList));
                if (status == "Called the elevator")
                {
                    GoEmtyToCall();
                }
            }
            else
            {
                if (CurrentFloor == floor && ElevatorList[0] != floor && Status != "Signal Overload")
                {
                    ElevatorList.Insert(0, floor);
                    FloorsInTheDirection++;
                }
                else
                {
                    switch ((Math.Sign(CurrentFloor - ElevatorList[0]) == Math.Sign(CurrentFloor - floor)) || (Math.Sign(CurrentFloor - ElevatorList[0]) == 0 && ElevatorList.Count > 1 && Math.Sign(CurrentFloor - ElevatorList[1]) == Math.Sign(CurrentFloor - floor)))
                    {
                    case true:
                        for (int i = 0; i < FloorsInTheDirection; i++)
                        {
                            if (Math.Abs(CurrentFloor - ElevatorList[i]) > Math.Abs(CurrentFloor - floor))
                            {
                                ElevatorList.Insert(i, floor);
                                FloorsInTheDirection++;
                                flag = true;
                                break;
                            }

                            if (Math.Abs(CurrentFloor - ElevatorList[i]) == Math.Abs(CurrentFloor - floor))
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            ElevatorList.Insert(FloorsInTheDirection, floor);
                            FloorsInTheDirection++;
                        }
                        break;

                    case false:
                        if (ElevatorList.Count == FloorsInTheDirection)
                        {
                            ElevatorList.Insert(FloorsInTheDirection, floor);
                        }
                        else
                        {
                            for (int i = FloorsInTheDirection; i < ElevatorList.Count; i++)
                            {
                                if (Math.Abs(ElevatorList[FloorsInTheDirection - 1] - ElevatorList[i]) > Math.Abs(ElevatorList[FloorsInTheDirection - 1] - floor))
                                {
                                    ElevatorList.Insert(i, floor);
                                    flag = true;
                                    break;
                                }

                                if (ElevatorList[i] == floor)
                                {
                                    flag = true;
                                    break;
                                }
                            }
                            if (!flag)
                            {
                                ElevatorList.Insert(ElevatorList.Count, floor);
                            }
                        }
                        break;
                    }
                    //   AddFloorList?.Invoke(floor);
                    EventUpdateElevatorList?.Invoke(String.Join(" ", ElevatorList));
                }
            }
        }