Example #1
0
 /// <summary>
 /// Makes the guest go to the cinema
 /// </summary>
 private void _getToCinema()
 {
     if (Path.Any())
     {
         _Move();
     }
     else if (!(Area is Cinema))
     {
         SetPath(Hotel.GetArea(Area, typeof(Cinema)));
         FinalDes = Hotel.GetArea(Area, typeof(Cinema));
     }
     else
     {
         if (Area.AreaStatus == AreaStatus.PLAYING_MOVIE)
         {
             Status   = MovableStatus.WATCHING;
             _hteTime = Hotel.HowLongWillMovieTake() + Path.Count();
         }
         else
         {
             Status   = MovableStatus.WAITING_TO_START;
             _hteTime = ((Cinema)Area).Duration;
         }
     }
 }
Example #2
0
        // Important note:
        // This list contains a fair amount of code duplication
        // this was the cause of simultaneously working on event implementation
        // we made this choice because of the limited time we had to implement these
        // as cause the actions list has become to big and needs a good refactor
        // there is no time for this so it is an issue that needs to be rethought in the fututure

        /// <summary>
        /// Sets variables for evacuation
        /// </summary>
        private void _EvacuateSequence()
        {
            SetPath(Hotel.GetArea(typeof(Reception)));
            FinalDes   = Hotel.GetArea(typeof(Reception));
            Status     = MovableStatus.EVACUATING;
            LastStatus = MovableStatus.EVACUATING;
        }
Example #3
0
 /// <summary>
 /// Creates an receptionist that can work with the hotel
 /// </summary>
 /// <param name="position">The position of the receptionist</param>
 /// <param name="hotel">The hotel in which the receptionist is located</param>
 public Receptionist(Point position, Hotel hotel)
 {
     Position = position;
     Hotel    = hotel;
     Area     = hotel.GetArea(typeof(Reception));
     Status   = MovableStatus.IDLE;
     HotelEventManager.Register(this);
 }
Example #4
0
        /// <summary>
        /// Sets the parameter from the builder file and the jsonfile
        /// </summary>
        /// <param name="position">The position of the elevator cart</param>
        /// <param name="hotel">The hotel in which the elevator cart is located</param>
        /// <param name="capacity">The capacity of the elevator cart</param>
        public ElevatorCart(Point position, Hotel hotel, int capacity)
        {
            Hotel    = hotel;
            Capacity = capacity;
            Status   = MovableStatus.IDLE;
            Position = position;
            Area     = Hotel.GetArea(Position);

            ((Elevator)Area).ElevatorCart = this;
        }
Example #5
0
 /// <summary>
 /// Checks if there is an evacuation
 /// </summary>
 private void Idle()
 {
     if (Status == MovableStatus.EVACUATING || LastStatus == MovableStatus.EVACUATING)
     {
         SetPath(Hotel.GetArea(typeof(Reception)));
         FinalDes   = Hotel.GetArea(typeof(Reception));
         Status     = MovableStatus.EVACUATING;
         LastStatus = MovableStatus.EVACUATING;
         return;
     }
 }
Example #6
0
        /// <summary>
        /// Leaves the elevator and assigns the correct status
        /// </summary>
        private void _LeavingElevator()
        {
            if (Status == MovableStatus.EVACUATING || LastStatus == MovableStatus.EVACUATING)
            {
                SetPath(Hotel.GetArea(typeof(Reception)));
                FinalDes   = Hotel.GetArea(typeof(Reception));
                Status     = MovableStatus.EVACUATING;
                LastStatus = MovableStatus.EVACUATING;
                return;
            }

            SetPath(FinalDes);

            Path   = new Queue <IArea>(Dijkstra.GetShortestPathDijkstra(Area, FinalDes));
            Status = LastStatus;
        }
Example #7
0
 /// <summary>
 /// Moves the guest to the fitness
 /// </summary>
 private void _goToFitness()
 {
     if (Path.Any())
     {
         _Move();
     }
     else if (!(Area is Fitness))
     {
         SetPath(Hotel.GetArea(Area, typeof(Fitness)));
         FinalDes = Hotel.GetArea(Area, typeof(Fitness));
     }
     else
     {
         Status   = MovableStatus.WORKING_OUT;
         _hteTime = rnd.Next(1, 7);
     }
 }
Example #8
0
        /// <summary>
        /// Removes the guest from the hotel
        /// </summary>
        private void _removeMe()
        {
            if (Path.Any())
            {
                _Move();
            }
            else
            {
                SetPath(Hotel.GetArea(typeof(Reception)));
                FinalDes = Hotel.GetArea(typeof(Reception));
            }

            if (Area is Reception)
            {
                Hotel.RemoveGuest(this);
            }
        }
Example #9
0
 /// <summary>
 /// Makes the guest go get food and find the closest restaurant
 /// </summary>
 private void _getFood()
 {
     if (Path.Any())
     {
         _Move();
     }
     else if (!(Area is Restaurant))
     {
         SetPath(Hotel.GetArea(Area, typeof(Restaurant)));
         FinalDes = Hotel.GetArea(Area, typeof(Restaurant));
     }
     else
     {
         Status   = MovableStatus.EATING;
         _hteTime = ((Restaurant)Area).Duration;
     }
 }
Example #10
0
        /// <summary>
        /// Creating a maid to use in the hotel
        /// </summary>
        /// <param name="startLocation">The location in the hotel the maid is first put on after creation</param>
        /// <param name="hotel">The hotel the maid works in</param>
        public Maid(Point startLocation, Hotel hotel)
        {
            Hotel    = hotel;
            Position = startLocation;
            Area     = Hotel.GetArea(Position);

            Status = MovableStatus.IDLE;

            HotelEventManager.Register(this);

            Actions.Add(MovableStatus.IDLE, _IsSomthingInQueue);
            Actions.Add(MovableStatus.GOING_TO_ROOM, _GoToRoom);
            Actions.Add(MovableStatus.CLEANING, _Cleaning);
            Actions.Add(MovableStatus.ELEVATOR_REQUEST, _CallElevator);
            Actions.Add(MovableStatus.LEAVING_ELEVATOR, _LeavingElevator);
            Actions.Add(MovableStatus.WAITING_FOR_ELEVATOR, Idle);
            Actions.Add(MovableStatus.EVACUATING, _Evacuate);
            Actions.Add(MovableStatus.IN_ELEVATOR, null);
        }
Example #11
0
        /// <summary>
        /// Makes the guest checkout
        /// </summary>
        private void _getCheckOut()
        {
            if (Path.Any())
            {
                _Move();
                Status            = MovableStatus.CHECKING_OUT;
                MyRoom.AreaStatus = AreaStatus.NEED_CLEANING;
            }

            else if (!(Area is Reception))
            {
                SetPath(Hotel.GetArea(Area, typeof(Reception)));
                FinalDes = Hotel.GetArea(Area, typeof(Reception));
            }
            else
            {
                _removeMe();
            }
        }
Example #12
0
        /// <summary>
        /// Makes the guest evacuate
        /// </summary>
        private void _Evacuate()
        {
            SetPath(Hotel.GetArea(typeof(Reception)));
            FinalDes = Hotel.GetArea(typeof(Reception));

            if (Hotel.IsHotelSafe())
            {
                if (_hteTime == _hteCalculateCounter)
                {
                    Status = MovableStatus.GOING_TO_ROOM;
                }
                else
                {
                    _hteCalculateCounter++;
                }
            }
            else if (Path.Any())
            {
                _Move();
            }
        }
Example #13
0
        /// <summary>
        /// Calls The Elevator
        /// </summary>
        private void _CallElevator()
        {
            if (Status == MovableStatus.EVACUATING || LastStatus == MovableStatus.EVACUATING)
            {
                SetPath(Hotel.GetArea(typeof(Reception)));
                FinalDes   = Hotel.GetArea(typeof(Reception));
                Status     = MovableStatus.EVACUATING;
                LastStatus = MovableStatus.EVACUATING;
                return;
            }

            if (Path.Any())
            {
                _Move();
            }
            else if (Area is Elevator && WantsElevator)
            {
                Hotel.CallElevator(this);
                WantsElevator = false;
                Status        = MovableStatus.WAITING_FOR_ELEVATOR;
            }
        }
Example #14
0
        /// <summary>
        /// This function pust the status of the elevator to UP which means the position of Y is going minus 1
        /// </summary>
        private void _elevatorGoesUp()
        {
            //If for some reason the Down list is bigger we change the status and elevator will go down instead of going up
            if (Up.Count == 0 && Down.Count != 0)
            {
                this.Status = MovableStatus.DOWN;
                PerformAction();
            }
            else
            {
                Position = new Point(Position.X, Position.Y - 1);
                Area     = Hotel.GetArea(Position);

                for (int i = 0; i < Up.Count; i++)
                {
                    if (Up[i] == Position.Y)
                    {
                        Up.RemoveAt(i);
                        break;
                    }
                }
            }
        }
Example #15
0
        /// <summary>
        /// The elevator will always go down by 1 as long as the downlist is filled, which means the position of Y is going plus 1
        /// </summary>
        private void _elevatorGoesDown()
        {
            //Extra check if the uplist is suddenly bigger than the downlist we change the status
            if (Up.Count != 0 && Down.Count == 0)
            {
                this.Status = MovableStatus.UP;
                PerformAction();
            }
            else
            {
                Position = new Point(Position.X, Position.Y + 1);
                Area     = Hotel.GetArea(Position);

                for (int i = 0; i < Down.Count; i++)
                {
                    if (Down[i] == Position.Y)
                    {
                        Down.RemoveAt(i);
                        break;
                    }
                }
            }
        }
Example #16
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();
            }
        }
Example #17
0
        /// <summary>
        /// Checks in the guest
        /// </summary>
        private void _checkIn()
        {
            if (Path.Any())
            {
                _Move();
            }
            else if (Area is Reception)
            {
                if (((Reception)Area).EnterArea(this))
                {
                    if (Hotel.GetArea(RoomRequest) is null)
                    {
                        Status = MovableStatus.LEAVING;
                    }
                    else
                    {
                        IArea newRoom = Hotel.GetArea(RoomRequest);
                        SetPath(Hotel.GetArea(RoomRequest));
                        newRoom.AreaStatus = AreaStatus.OCCUPIED;
                        FinalDes           = newRoom;
                        MyRoom             = newRoom;


                        switch (((Room)MyRoom).Classification)
                        {
                        case 1:
                            MyRoom.Art = Properties.Resources.room_one_star_locked;
                            break;

                        case 2:
                            MyRoom.Art = Properties.Resources.room_two_star_locked;
                            break;

                        case 3:
                            MyRoom.Art = Properties.Resources.room_three_star_locked;
                            break;

                        case 4:
                            MyRoom.Art = Properties.Resources.room_four_star_locked;
                            break;

                        case 5:
                            MyRoom.Art = Properties.Resources.room_five_star_locked;
                            break;

                        default:
                            break;
                        }

                        ((Reception)Area).CheckInQueue.Dequeue();
                        Status = MovableStatus.GOING_TO_ROOM;
                    }
                }
                else if (!((Reception)Area).CheckInQueue.Contains(this))
                {
                    ((Reception)Area).CheckInQueue.Enqueue(this);
                }
                else
                {
                    // Kill timer
                }
            }
        }