Beispiel #1
0
        /// <summary>
        /// Each time a PerformAction is called we check what Status the elevator
        /// is in and we are removing the guests from the RemoveGuest list
        /// Because we have a "Smart" elevator, the elevator will check wich list is bigger and then handle the biggest list first until it's empty
        /// which means that the elevator will always make the uplist smaller and if the list is equal to zero the elevator will go down
        ///
        /// This is just like in real life. If there are 3 people, each person is on a different floor
        /// and lets say guestA presses the button first and the elevator is also on floor 3 now
        /// GuestA,B wants to go down but guestC wants to go up.
        ///
        /// which means our Up list is filled with guestC and our Down list is filled with guestA and B
        /// this will lead to that our down list is bigger and the lift will first drop off guestA and B to the requested floor and will then pick up guestC
        /// this elevator will not jump up and down
        /// floor: 5
        /// floor: 4 guestC
        /// floor: 3 guestA       elevator
        /// floor: 2 guestB
        /// floor: 1
        /// </summary>
        public void PerformAction()
        {
            //We wanted to use a foreach loop but because of the threading we had to do a forloop
            //Difference between foreach and forloop is that a foreach will crash when something is changed during the simulation and forloop can adjust
            RemoveGuests.Clear();
            for (int i = 0; i < GuestList.Count; i++)
            {
                if (GuestList[i] is IMovable g)
                {
                    if (Position.Y == g.FinalDes.Position.Y)
                    {
                        g.Status = MovableStatus.LEAVING_ELEVATOR;
                        g.Area   = Hotel.GetArea(Position);
                        RemoveGuests.Add(GuestList[i]);
                    }
                }
            }
            //Second forloop to remove the guest in order to not have an error
            for (int i = 0; i < RemoveGuests.Count; i++)
            {
                GuestList.Remove(RemoveGuests[i]);
            }
            RemoveGuests.Clear();

            //Removing Down list items
            if (Down.Count != 0 && Down[0] == Position.Y)
            {
                Down.RemoveAt(0);
            }
            //Removing Up list items
            if (Up.Count != 0 && Up[0] == Position.Y)
            {
                Up.RemoveAt(0);
            }

            //If the status is up we perform the method _elevatorGoesup();
            if (Status == MovableStatus.UP)
            {
                _elevatorGoesUp();
            }
            //If the status is down we perform the method _elevatorGoesDown() with an extra check that the elevator will not leave the field.
            else if (Status == MovableStatus.DOWN && Position.Y < Hotel.HotelHeight)
            {
                _elevatorGoesDown();
            }
            else
            {
                Status = MovableStatus.IDLE;
            }
            //In order to draw the guests correctly on the field we change the position to the elevator position
            foreach (IMovable human in GuestList)
            {
                human.Position = Position;
            }
            AddDestinationFloor();

            //If both lists are empty we are changing the elevatorCart status and the elevator will go down
            if (Up.Count == 0 && Down.Count == 0)
            {
                Status = MovableStatus.IDLE;
            }

            if (Status == MovableStatus.IDLE)
            {
                _ElevatorDoesNothing();
            }
        }
Beispiel #2
0
 /// <summary>
 /// Sets the properties to use dijkstra
 /// </summary>
 /// <param name="hotel">The current hotel</param>
 public static void IntilazeDijkstra(Hotel hotel)
 {
     Hotel = hotel;
     Areas = Hotel.HotelAreas;
 }