コード例 #1
1
        public Building()
        {
            //Set exitLocation on 0 floor
            exitLocation = 677;

            //Initialize floors
            arrayOfAllFloors = new Floor[4];
            arrayOfAllFloors[0] = new Floor(this, 0, 373);
            arrayOfAllFloors[1] = new Floor(this, 1, 254);
            arrayOfAllFloors[2] = new Floor(this, 2, 144);
            arrayOfAllFloors[3] = new Floor(this, 3, 32);

            //Initialize elevators (each elevator starts on randomly choosen floor)
            arrayOfAllElevators = new Elevator[3];
            Random random = new Random();

            arrayOfAllElevators[0] = new Elevator(this, 124, arrayOfAllFloors[random.Next(arrayOfAllFloors.Length)]);
            arrayOfAllElevators[1] = new Elevator(this, 210, arrayOfAllFloors[random.Next(arrayOfAllFloors.Length)]);
            arrayOfAllElevators[2] = new Elevator(this, 295, arrayOfAllFloors[random.Next(arrayOfAllFloors.Length)]);

            //Initialize list of all people inside (to track who's inside and need to be animated)
            ListOfAllPeopleWhoNeedAnimation = new List<Passenger>();

            //Initialize ElevatorManager object
            ElevatorManager = new ElevatorManager(ArrayOfAllElevators, ArrayOfAllFloors);
        }
コード例 #2
1
        public ElevatorManager(Elevator[] ArrayOfAllElevators, Floor[] ArrayOfAllFloors)
        {
            //Initialize array with elevators
            this.arrayOfAllElevators = ArrayOfAllElevators;

            //Subscribe to elevators' events
            for (int i = 0; i < arrayOfAllElevators.Length; i++)
            {
                arrayOfAllElevators[i].ElevatorIsFull += new EventHandler(ElevatorManager_ElevatorIsFull); //Subscribe to all ElevatorIsFull events
            }

            //Initialize array with floors
            this.arrayOfAllFloors = ArrayOfAllFloors;

            //Initialize list of free elevators
            this.listOfAllFreeElevators = new List<Elevator>();

            //Launch timer to periodically check, if some floor doesn't need an elevator
            this.floorChecker = new System.Timers.Timer(1000);
            this.floorChecker.Elapsed += new ElapsedEventHandler(this.ElevatorManager_TimerElapsed);
            this.floorChecker.Start();
        }
コード例 #3
0
ファイル: Floor.cs プロジェクト: phaethom/ElevatorSimulator
        public void AddRemoveElevatorToTheListOfElevatorsWaitingHere(Elevator ElevatorToAddOrRemove, bool AddFlag)
        {
            lock (locker) //Few elevators can try to add/remove themselfs at the same time
            {
                if (AddFlag) //Add elevator
                {
                    //Add elevator to the list
                    listOfElevatorsWaitingHere.Add(ElevatorToAddOrRemove);

                    //Subscribe to an event, rised when passenger entered the elevator
                    ElevatorToAddOrRemove.PassengerEnteredTheElevator += new EventHandler(this.Floor_PassengerEnteredTheElevator);
                }
                else //Remove elevator
                {
                    //Remove elevator from the list
                    listOfElevatorsWaitingHere.Remove(ElevatorToAddOrRemove);

                    //Unsubscribe from an event, rised when passenger entered the elevator
                    ElevatorToAddOrRemove.PassengerEnteredTheElevator -= this.Floor_PassengerEnteredTheElevator;
                }
            }
        }
コード例 #4
0
ファイル: Floor.cs プロジェクト: gform/ElevatorSimulator
        public void AddRemoveElevatorToTheListOfElevatorsWaitingHere(Elevator ElevatorToAddOrRemove, bool AddFlag)
        {
            lock (locker)    //Few elevators can try to add/remove themselfs at the same time
            {
                if (AddFlag) //Add elevator
                {
                    //Add elevator to the list
                    listOfElevatorsWaitingHere.Add(ElevatorToAddOrRemove);

                    //Subscribe to an event, rised when passenger entered the elevator
                    ElevatorToAddOrRemove.PassengerEnteredTheElevator += new EventHandler(this.Floor_PassengerEnteredTheElevator);
                    logWriter.Log($"Elevator ({ElevatorToAddOrRemove.Id}) added to the floor ({FloorIndex}).");
                }
                else //Remove elevator
                {
                    //Remove elevator from the list
                    listOfElevatorsWaitingHere.Remove(ElevatorToAddOrRemove);

                    //Unsubscribe from an event, rised when passenger entered the elevator
                    ElevatorToAddOrRemove.PassengerEnteredTheElevator -= this.Floor_PassengerEnteredTheElevator;
                    logWriter.Log($"Elevator ({ElevatorToAddOrRemove.Id}) removed from the floor ({FloorIndex}).");
                }
            }
        }
コード例 #5
0
 public ElevatorEventArgs(Elevator ElevatorWhichArrived)
 {
     this.ElevatorWhichRisedAnEvent = ElevatorWhichArrived;
 }
コード例 #6
0
 private static void SendAnElevator(Elevator elevator, Floor floor)
 {
     elevator.AddNewFloorToTheList(floor);
     ThreadPool.QueueUserWorkItem(delegate { elevator.PrepareElevatorToGoToNextFloorOnTheList(); });
 }
コード例 #7
0
        private void SendAnElevator(Elevator ElevatorToSend, Floor TargetFloor)
        {
            ElevatorToSend.AddNewFloorToTheList(TargetFloor);

            //Create new thread and send the elevator
            ThreadPool.QueueUserWorkItem(delegate { ElevatorToSend.PrepareElevatorToGoToNextFloorOnTheList(); });
        }
コード例 #8
0
 public ElevatorEventArgs(Elevator ElevatorWhichArrived)
 {
     this.ElevatorWhichRisedAnEvent = ElevatorWhichArrived;
 }
コード例 #9
0
        private void GetOutOfTheElevator(Elevator ElevatorWhichArrived)
        {
            //Remove passenger from elevator
            ElevatorWhichArrived.RemovePassenger(this);

            //Leave the building
            this.LeaveTheBuilding();
        }
コード例 #10
0
        private void GetInToTheElevator(Elevator ElevatorToGetIn)
        {
            //Rise an event
            ElevatorToGetIn.OnPassengerEnteredTheElevator(new PassengerEventArgs(this));

            //Unsubscribe from an event for current floor
            this.currentFloor.ElevatorHasArrivedOrIsNotFullAnymore -= this.Passenger_ElevatorHasArrivedOrIsNoteFullAnymore;

            //Move the picture on the UI
            this.MovePassengersGraphicHorizontally(ElevatorToGetIn.GetElevatorXPosition());

            //Make PassengerControl invisible
            this.visible = false;

            //Update myElevator
            this.myElevator = ElevatorToGetIn;
        }
コード例 #11
0
        private bool ElevatorsDirectionIsNoneOrOk(Elevator ElevatorOnMyFloor)
        {
            //Check if elevator has more floors to visit
            if (ElevatorOnMyFloor.GetElevatorDirection() == this.PassengerDirection)
            {
                return true; //Elevator direction is OK
            }
            else if (ElevatorOnMyFloor.GetElevatorDirection() == Direction.None)
            {
                return true; //If an elevator has no floors to visit, then it is always the right elevator
            }

            return false; //Elevator direction is NOT OK
        }