Пример #1
0
        /// <summary>
        /// checks if anything has happened in the hotel.
        /// if anything has happend checks what happend and makes sure everyone involved reacts appopriatly.
        /// </summary>
        /// <param name="simplePath"></param>
        /// <param name="hotel">the hotel that is simulated</param>
        /// <param name="persons">every person inside of the hotel</param>
        /// <param name="reception">the reception in the lobby</param>
        /// <param name="customers">every customer inside of the hotel</param>
        /// <param name="listener">the observer of the hotel</param>
        /// <param name="lobby">the lobby inside of the hotel</param>
        /// <param name="elevator">the elevator inside of the hotel</param>
        /// <param name="cleaner">the main cleaner inside of the hotel, this is the only cleaner qualified to clean emergencies</param>
        /// <param name="cleaners">the cleaners in the hotel, they can perform cleaning actions</param>
        /// <param name="gameTime">the runtime of the hotel</param>
        /// <param name="RoomQueue">The dirty rooms in order of cleaning</param>
        public void CheckEvents(SimplePath simplePath, Hotel hotel, List <IPerson> persons, Reception reception, List <Customer> customers, EventListener listener, Lobby lobby, Elevator elevator, Cleaner cleaner, List <Cleaner> cleaners, GameTime gameTime, Queue <Room> RoomQueue)
        {
            foreach (var evt in listener.Events.ToList())
            {
                if (!_evac)
                {
                    if (evt.EventType == HotelEventType.CHECK_IN)
                    {
                        if (evt.Data != null)
                        {
                            foreach (var key in evt.Data.Keys)
                            {
                                Customer newCustomer = new Customer()
                                {
                                    Preferance = Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(evt.Data[key], "[^\\d]"))), Position = new Vector2(reception.QueuePosition / 4 + 1, 0), ID = Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(evt.Data.Keys.First(), "[^\\d]")))
                                };
                                persons.Add(newCustomer);
                                customers.Add(newCustomer);
                                reception.Enqueue(newCustomer);
                                elevator.Attach(newCustomer);
                            }
                        }
                        listener.Events.Remove(evt);
                    }
                    else if (evt.EventType == HotelEventType.CHECK_OUT)
                    {
                        foreach (var key in evt.Data.Keys)
                        {
                            var obj = from f in customers
                                      where (f.ID == Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(evt.Data.Values.First(), "[^\\d]"))))
                                      select f;
                            if (obj.Count() > 0)
                            {
                                obj.First().Destination = lobby.Position;
                                if (obj.First().Room != null)
                                {
                                    obj.First().Room.State = Room.RoomState.Dirty;
                                    obj.First().Room  = null;
                                    obj.First().Route = simplePath.GetRoute(obj.First().Position, obj.First().Destination);
                                }
                                elevator.Detach(obj.First());
                                persons.Remove(obj.First());
                                customers.Remove(obj.First());
                            }
                            listener.Events.Remove(evt);
                        }
                    }
                    else if (evt.EventType == HotelEventType.GOTO_FITNESS)
                    {
                        foreach (var key in evt.Data.Keys)
                        {
                            var obj = from f in customers
                                      where (f.ID == Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(evt.Data.Values.First(), "[^\\d]"))))
                                      select f;
                            int TijdsDuur = Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(evt.Data.Values.ElementAt(1), "[^\\d]")));


                            if (obj.Count() > 0)
                            {
                                obj.First().Destination = hotel.Areas.Where(a => a.AreaType == "Fitness").First().Position;
                                obj.First().Route       = simplePath.GetRoute(obj.First().Position, obj.First().Destination);
                                obj.First().WaitingTime = TijdsDuur;
                            }
                            listener.Events.Remove(evt);
                        }
                    }
                    else if (evt.EventType == HotelEventType.GOTO_CINEMA)
                    {
                        foreach (var key in evt.Data.Keys)
                        {
                            var obj = from f in customers
                                      where (f.ID == Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(evt.Data.Values.First(), "[^\\d]"))))
                                      select f;
                            if (obj.Count() > 0)
                            {
                                Cinema leukeCinema      = (Cinema)hotel.Areas.Where(a => a.AreaType == "Cinema").First();
                                obj.First().Destination = leukeCinema.Position;
                                obj.First().Route       = simplePath.GetRoute(obj.First().Position, obj.First().Destination);
                                leukeCinema.RunTime = int.MaxValue;
                                obj.First().WaitingTime = leukeCinema.RunTime;
                            }
                            listener.Events.Remove(evt);
                        }
                    }
                    else if (evt.EventType == HotelEventType.NEED_FOOD)
                    {
                        foreach (var key in evt.Data.Keys)
                        {
                            var obj = from f in customers
                                      where (f.ID == Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(evt.Data.Values.First(), "[^\\d]"))))
                                      select f;
                            if (obj.Count() > 0)
                            {
                                Restaurant restaurant   = (Restaurant)hotel.Areas.Where(a => a.AreaType == "Restaurant").First();
                                obj.First().Destination = restaurant.Position;
                                restaurant.HuidigeBezetting++;
                                obj.First().Route       = simplePath.GetRoute(obj.First().Position, obj.First().Destination);
                                obj.First().WaitingTime = restaurant.EatSpeed;
                            }
                            listener.Events.Remove(evt);
                        }
                    }
                    else if (evt.EventType == HotelEventType.START_CINEMA)
                    {
                        foreach (var key in evt.Data.Keys)
                        {
                            var obj = from f in hotel.Areas
                                      where (f.ID == Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(evt.Data.Values.First(), "[^\\d]"))))
                                      select f;

                            if (obj.Count() > 0)
                            {
                                Cinema beginnendeCinema = (Cinema)obj.First();
                                beginnendeCinema.Started = true;
                            }
                        }

                        listener.Events.Remove(evt);
                    }
                    else if (evt.EventType == HotelEventType.EVACUATE)
                    {
                        foreach (Person person in persons)
                        {
                            person.Destination = lobby.Position;
                            person.Route       = simplePath.GetRoute(person.Position, person.Destination);
                        }

                        List <Room> rooms = new List <Room>();
                        foreach (Room r in hotel.Areas.Where(r => r.AreaType == "Room"))
                        {
                            rooms.Add(r);
                        }
                        foreach (Room room in rooms.Where(r => r.State == Room.RoomState.Cleaning))
                        {
                            room.State = Room.RoomState.Dirty;
                        }
                        _evac = true;
                        listener.Events.Remove(evt);
                    }
                    else if (evt.EventType == HotelEventType.CLEANING_EMERGENCY)
                    {
                        foreach (var key in evt.Data.Keys)
                        {
                            var obj = from f in hotel.Areas
                                      where (f.ID == Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(evt.Data.Values.First(), "[^\\d]"))))
                                      select f;
                            int TijdsDuur = Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(evt.Data.Values.ElementAt(1), "[^\\d]")));
                            if (obj.First().GetType() == typeof(Room))
                            {
                                Room EmergRoom = (Room)obj.First();
                                EmergRoom.State = Room.RoomState.Emergency;
                            }
                        }

                        listener.Events.Remove(evt);
                    }
                    else
                    {
                        listener.Events.Remove(evt);
                    }
                }
            }
            if (_evac)
            {
                foreach (Person person in persons)
                {
                    if (person.Position == lobby.Position)
                    {
                        _countPeople++;

                        if (person.GetType() == typeof(Customer))
                        {
                            Customer escapeCustomer = (Customer)person;
                            escapeCustomer.WaitingTime = int.MaxValue;
                            escapeCustomer.Route.Clear();
                        }
                        if (person.GetType() == typeof(Cleaner))
                        {
                            Cleaner escapeCleaner = (Cleaner)person;
                            escapeCleaner.Evacuating            = true;
                            escapeCleaner.PassedTimeSinceUpdate = 0;
                        }
                    }
                }
                if (_countPeople == persons.Count)
                {
                    foreach (Person runPerson in persons)
                    {
                        if (runPerson.GetType() == typeof(Customer))
                        {
                            Customer runCustomer = (Customer)runPerson;
                            runCustomer.WaitingTime = 0;
                        }
                        else if (runPerson.GetType() == typeof(Cleaner))
                        {
                            Cleaner escapeCleaner = (Cleaner)runPerson;
                            escapeCleaner.Cleaning   = false;
                            escapeCleaner.Evacuating = false;
                        }
                    }
                    _evac = false;
                }
            }
            _countPeople = 0;
        }
        /// <summary>
        /// Creates an instance of the given AreaType and returns it.
        /// </summary>
        /// <param name="ID">ID of the Area</param>
        /// <param name="areaType">Type of Area</param>
        /// <param name="capacity">How many Humans can be in the Area at the same time</param>
        /// <param name="classification">The Classification of the Area</param>
        /// <param name="positionX">The horizontal point in the grid</param>
        /// <param name="positionY">The vertical point in the grid</param>
        /// <param name="width">The width of the Area</param>
        /// <param name="height">The height of the Area</param>
        /// <returns>An instance of the given AreaType (IArea)</returns>
        public static IArea Create(int ID, string areaType, int capacity, int classification, int positionX, int positionY, int width, int height)
        {
            EAreaType AreaType = StringToAreaType(areaType);

            switch (AreaType)
            {
                #region Facilities
            //If the AreaType is Cinema
            case EAreaType.Cinema:
                Cinema tempCinema = new Cinema();
                tempCinema.Create(ID, AreaType, capacity, classification, positionX, positionY, width, height);
                return(tempCinema);

            //If the AreaType is Restaurant
            case EAreaType.Restaurant:
                Restaurant tempRestaurant = new Restaurant();
                tempRestaurant.Create(ID, AreaType, capacity, classification, positionX, positionY, width, height);
                return(tempRestaurant);

            //If the AreaType is Fitness
            case EAreaType.Fitness:
                Fitness tempFitness = new Fitness();
                tempFitness.Create(ID, AreaType, capacity, classification, positionX, positionY, width, height);
                return(tempFitness);

                #endregion

                #region MoveAble Areas
            //If the AreaType is ElevatorShaft
            case EAreaType.ElevatorShaft:
                ElevatorShaft tempElevatorShaft = new ElevatorShaft();
                tempElevatorShaft.Create(ID, AreaType, capacity, classification, positionX, positionY, width, height);
                return(tempElevatorShaft);

            //If the AreaType is Hallway
            case EAreaType.Hallway:
                Hallway tempHallway = new Hallway();
                tempHallway.Create(ID, AreaType, capacity, classification, positionX, positionY, width, height);
                return(tempHallway);

            //If the AreaType is Staircase
            case EAreaType.Staircase:
                Staircase tempStaircase = new Staircase();
                tempStaircase.Create(ID, AreaType, capacity, classification, positionX, positionY, width, height);
                return(tempStaircase);

                #endregion

                #region Room
            //If the AreaType is Room
            case EAreaType.Room:
                Room tempRoom = new Room();
                tempRoom.Create(ID, AreaType, capacity, classification, positionX, positionY, width, height);
                return(tempRoom);

                #endregion

                #region Reception
            //If the AreaType is Reception
            case EAreaType.Reception:
                Reception tempReception = new Reception();
                tempReception.Create(ID, AreaType, capacity, classification, positionX, positionY, width, height);
                return(tempReception);

                #endregion
            }
            //If the given AreaType can't be found we will return null
            return(null);
        }