Esempio n. 1
0
 /// <summary>
 /// Removing locationtypes when there Dimension is a 0. You can see the Dimension of a locationtype has it's healthbar.
 /// We take the biggest most right collum of the hotel and send the position and Dimension to all locationtypes that get's notified
 /// Locationtypes compares those numbers to see if it's health(Dimension) has to be substracted
 /// When locationtype is being attacked and it's Dimension is at one, he will be deleted because every attacks removes one health(Dimension)
 /// </summary>
 public void DestroyLocationTypes()
 {
     // setting status on Godzilla so we can define how to interact by this
     StatusHotel = HotelEventType.GODZILLA;
     // When there are facilities, it will be attacked by the godzilla
     if (Facilities.Count != 0)
     {
         // Take the biggest locationtype by combining the xPosition and xDimension
         LocationType Biggest = Facilities.Aggregate((i1, i2) => (i1.Position.X + i1.Dimension.X) > (i2.Position.X + i2.Dimension.X) ? i1 : i2);
         // Visitor should die
         foreach (var specificVisitor in lobby.Visitors)
         {
             specificVisitor.Die();
         }
         // Cleaner should die
         foreach (var specificCleaner in lobby.Cleaners)
         {
             specificCleaner.Die();
         }
         // Loop trought all facilities to notify them
         for (int facility = 0; facility < Facilities.Count; facility++)
         {
             if (Facilities[facility].Notify(StatusHotel, Biggest.Position.X, Biggest.Dimension.X) == true)
             {
                 // When locationtypes tells us that his health is at one, he should be deleted because there is no use to set it at zero
                 if (Facilities[facility] is ElevatorShaft)
                 {
                     elevator = null;
                 }
                 Facilities.Remove(Facilities[facility]);
                 facility--;
             }
         }
         // When destroying is done, set status on NONE again
         StatusHotel = HotelEventType.NONE;
     }
 }
Esempio n. 2
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;
        }
Esempio n. 3
0
        /// <summary>
        /// This is where we create objects by reading a file
        /// Bases on the AreaType we can dynamically create objects of this Areatype
        /// We also create objects manually by creating the factory, we can send a string which identifies what kind of object we want to create
        /// We send the facility model to the being created object which he can initialize
        /// </summary>
        /// <param name="file"></param>
        private void CreateFactoryObjects(string file)
        {
            IFactory locationTypeFactory = Factory.AbstractFactory.Instance().Create("LocationType");
            // This fileReader object is made to read files and make objects out of it
            FileReader fileReader = new FileReader();
            // This code lets us write the layout into model
            List <Facility> facilitiesModels = fileReader.ReadLayoutFile(file);

            // We jump right into the models annd for every mode lwe create an object
            foreach (var item in facilitiesModels)
            {
                // Setting hte of the hte value in the facility model
                item.Hte = this.hte;
                // Bases on the areaytype we create items
                LocationType AreaType = locationTypeFactory.CreateCreatableObject(item.AreaType, item) as LocationType;
                // We add the item in an list so we can make use of it
                Facilities.Add(AreaType);
            }



            // get the object with the biggest x-position. Now we can add the x position and Dimension * width to give stairs te correct position
            LocationType biggest = Facilities.Aggregate((i1, i2) => i1.Position.X > i2.Position.X ? i1 : i2);

            // We need the max y-position from the facility list so we can create the correct amount of stairs and elevatorshafts
            int maxYposHotel = Facilities.Max(element => element.Position.Y);

            // We need to know the minimum x-position because if the lowest x-position is zero, then the elevatorshafts has to have a position aswell.
            int minXposHotel = Facilities.Min(element => element.Position.X);

            // If the lowest x-position is zero or lower, we subtract 1, now we got minus 1 or even lesser, depends on how low the x-position is.
            if (minXposHotel <= 0)
            {
                minXposHotel -= 1;
            }
            // Else we keep it at 0, we now can draw multiple layout files without having to worry about the positions given to us.
            else
            {
                minXposHotel = 0;
            }
            // In the method ChangePositionHotel, I will continiue this comment.....



            // Where we will store information to send to locationtype
            Facility specs;

            // Where we will store the created ID. Locationtype will set this as it's ID.
            int CreatedID = 0;

            // This is where lobby is created
            CreatedID = Facilities.Max(element => element.ID) + 1;
            specs     = new Facility()
            {
                AreaType = "Lobby", Dimension = new Point(biggest.Position.X + Math.Abs(minXposHotel) + biggest.Dimension.X - 1, 1), Position = new Point(1 + minXposHotel, 0), ID = CreatedID, Hte = this.hte
            };
            LocationType Lobby = locationTypeFactory.CreateCreatableObject("Lobby", specs) as LocationType;

            lobby = Lobby as Lobby;
            Facilities.Add(Lobby);

            // this is the elevatorhall where elevator moves in
            for (int i = 0; i <= maxYposHotel; i++)
            {
                CreatedID = Facilities.Max(element => element.ID) + 1;
                specs     = new Facility()
                {
                    AreaType = "ElevatorHall", Position = new Point(minXposHotel, i), Dimension = new Point(1, 1), ID = CreatedID, Hte = this.hte
                };
                LocationType elevatorHall = locationTypeFactory.CreateCreatableObject("ElevatorHall", specs) as LocationType;
                Facilities.Add(elevatorHall);

                if (i == 0)
                {
                    specs = new Facility()
                    {
                        ElevatorShaft = elevatorHall, Hte = this.hte
                    };
                    elevator = locationTypeFactory.CreateCreatableObject("Elevator", specs) as Elevator;
                }
                (elevatorHall as ElevatorShaft).Attach(elevator);
            }

            // Staircase will be set on the last row of the hotel
            for (int i = 0; i <= maxYposHotel; i++)
            {
                CreatedID = Facilities.Max(element => element.ID) + 1;
                specs     = new Facility()
                {
                    AreaType = "Staircase", Position = new Point((biggest.Position.X + biggest.Dimension.X), i), Dimension = new Point(1, 1), ID = CreatedID, Hte = this.hte
                };
                LocationType stairCase = locationTypeFactory.CreateCreatableObject("Staircase", specs) as LocationType;
                Facilities.Add(stairCase);
            }


            // Give Lobby the rooms because we see it as the reception, so the reception has to manage visitors.
            // Visitors dont leave the place so their world is all facilities combined.
            for (int i = 0; i < Facilities.Count; i++)
            {
                if (Facilities[i].AreaType.Equals("Room"))
                {
                    lobby.GetRoom((Facilities[i] as Room));
                }
            }
            pathfinding = new PathFinding(Facilities);
            // Change position from hotel if there are negative coordinations (like position.x = -1)
            ChangePositionLocationtypes();
            InitialiseHotelDimension();
        }