Exemple #1
0
 /// <summary>
 /// after customer is done waiting he returns to his room.
 /// if he wants to enter the restaurant and it's full he also returns to his room.
 /// </summary>
 /// <param name="gameTime"></param>
 /// <param name="simplePath"></param>
 /// <param name="hotel"></param>
 public void ReturnToRoom(GameTime gameTime, SimplePath simplePath, Hotel hotel)
 {
     if (Room != null && Position != Room.Position && Position == Destination)
     {
         Restaurant restaurant = (Restaurant)hotel.Areas.Where(a => a.AreaType == "Restaurant").FirstOrDefault();
         float      tussenTijd = gameTime.ElapsedGameTime.Milliseconds;
         tussenTijd             /= 1000;
         _passedTimeSinceUpdate += tussenTijd;
         if (_passedTimeSinceUpdate >= WaitingTime / HotelEventManager.HTE_Factor)
         {
             Destination = Room.Position;
             Route       = simplePath.GetRoute(Position, Destination);
             if (Position == restaurant.Position)
             {
                 restaurant.HuidigeBezetting--;
             }
         }
         if (Position == restaurant.Position && restaurant.Capacity < restaurant.HuidigeBezetting)
         {
             Destination = Room.Position;
             Route       = simplePath.GetRoute(Position, Destination);
             restaurant.HuidigeBezetting--;
         }
     }
 }
Exemple #2
0
 /// <summary>
 /// Gets the next room that needs to be cleaned
 /// </summary>
 /// <param name="gameTime"></param>
 /// <param name="simplePath"></param>
 /// <param name="RoomQueue"></param>
 public void GetRoom(GameTime gameTime, SimplePath simplePath, Queue <Room> RoomQueue)
 {
     if (!Evacuating)
     {
         if (RoomQueue.Count > 0)
         {
             if (Room != null && !Cleaning)
             {
                 Room = RoomQueue.First();
                 RoomQueue.Dequeue();
                 Room.State  = RoomState.Cleaning;
                 Cleaning    = true;
                 Destination = Room.Position;
                 Route       = simplePath.GetRoute(Position, Destination);
             }
         }
         if (Position == VasteLocatie && Room.State == RoomState.Cleaning)
         {
             Room.State = RoomState.Dirty;
         }
         if (Room != null && Position == Destination && Cleaning == true)
         {
             Clean(Room, gameTime, simplePath);
         }
     }
 }
        /// <summary>
        /// finds an empty room for every customer and sends them to their room
        /// </summary>
        /// <param name="hotel"></param>
        /// <param name="simplePath"></param>
        public void HelpQueue(Hotel hotel, SimplePath simplePath)
        {
            if (_queue.Count > 0)
            {
                Customer helpMe = _queue.Dequeue();
                helpMe.Room        = GetFreeRoom(helpMe.Preferance, hotel);
                helpMe.Room.State  = Room.RoomState.Booked;
                helpMe.Destination = helpMe.Room.Position;
                helpMe.Route       = simplePath.GetRoute(helpMe.Position, helpMe.Destination);

                QueuePosition--;
            }
        }
Exemple #4
0
 /// <summary>
 /// customer checks if the cinema he wants to enter has started.
 /// if the cinema is already running a movie before he has entered he returns to his room.
 /// </summary>
 /// <param name="simplePath"></param>
 /// <param name="cinema"></param>
 public void CheckCinema(SimplePath simplePath, Cinema cinema)
 {
     if (cinema != null)
     {
         if (Destination == cinema.Position && Position != cinema.Position && cinema.Started)
         {
             Destination = new Vector2(cinema.Position.X - 1f, cinema.Position.Y);
             Route       = simplePath.GetRoute(Position, Destination);
         }
         if (Destination.X == cinema.Position.X - 1f && Position != cinema.Position && cinema.Started)
         {
             WaitingTime = int.MaxValue;
         }
     }
 }
Exemple #5
0
        /// <summary>
        /// cleaner starts cleaning.
        /// after cleaning is finished the room is free and the cleaner goes back to the optimal position.
        /// </summary>
        /// <param name="room"></param>
        /// <param name="gameTime"></param>
        /// <param name="simplePath"></param>
        private void Clean(Room room, GameTime gameTime, SimplePath simplePath)
        {
            if (Cleaning && Room == null)
            {
                Cleaning = false;
            }
            float tussenTijd = gameTime.ElapsedGameTime.Milliseconds;

            tussenTijd            /= 1000;
            passedTimeSinceUpdate += tussenTijd;
            if (passedTimeSinceUpdate >= CleaningSpeed / HotelEventManager.HTE_Factor)
            {
                room.State  = Room.RoomState.Free;
                Cleaning    = false;
                Destination = VasteLocatie;
                Route       = simplePath.GetRoute(Position, Destination);
            }
        }
Exemple #6
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>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here
            if (Keyboard.GetState().IsKeyDown(Keys.U))
            {
                _isPaused         = false;
                _menuForm.Visible = false;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.P) && !_isPaused)
            {
                _isPaused         = true;
                _menuForm.Visible = true;
                _menuForm.ReInitListboxes();
                if (HotelEventManager.Running)
                {
                    HotelEventManager.Pauze();
                }
            }
            if (_isPaused)
            {
                _isPaused = _menuForm.Visible;
            }
            else
            {
                if (HotelEventManager.Running)
                {
                    HotelEventManager.Pauze();
                }
                ReloadAfterForm();

                _menuForm.Visible = false;
                _eventChecker.CheckEvents(_simplePath, _hotel, _persons, _reception, _customers, listener, _lobby, _elevator, _cleaner, _cleaners, gameTime, _roomQueue);

                _cleaner.SearchRoom(_hotel, _roomQueue);
                _cleaner2.SearchRoom(_hotel, _roomQueue);

                _cleaner.GetRoom(gameTime, _simplePath, _roomQueue);
                _cleaner2.GetRoom(gameTime, _simplePath, _roomQueue);

                _roomQueue.Clear();

                foreach (IPerson person in _persons)
                {
                    if (person.Sprite == null)
                    {
                        person.LoadContent(Content);
                    }
                    person.Update(gameTime);
                }
                _reception.HelpQueue(_hotel, _simplePath);
                _elevator.InitWaitingFloors();
                _elevator.Update(gameTime);

                _huidigeCinema.CheckCinema(gameTime, _hotel, _huidigeCinema, _simplePath, _customers);

                if (_customers.Count != 0)
                {
                    foreach (Customer customer in _customers)
                    {
                        customer.ReturnToRoom(gameTime, _simplePath, _hotel);
                        customer.CheckCinema(_simplePath, _huidigeCinema);
                    }
                }
                foreach (Person person in _persons)
                {
                    if (person.Position != null && person.Destination != null && person.Route != null)
                    {
                        if (person.Position != person.Destination && person.Route.Count == 0)
                        {
                            person.Route = _simplePath.GetRoute(new Vector2((float)Math.Round(person.Position.X, 0), (float)Math.Round(person.Position.Y, 0)), person.Destination);
                        }
                    }
                }
                base.Update(gameTime);
                if (!HotelEventManager.Running)
                {
                    HotelEventManager.Pauze();
                }
            }
        }