예제 #1
0
        public void CleanerGhostConstructor()
        {
            GuestRoom room    = new GuestRoom(1, new Point(1, 0), new Point(1, 1), 1);
            EmptyRoom outside = new EmptyRoom(0, new Point(0, 0), new Point(1, 1));

            outside.Entrance = true;

            room.Neighbors.Add(Direction.West, room);
            outside.Neighbors.Add(Direction.East, room);

            CleanerGhost ghost = new CleanerGhost(room);

            Assert.IsNotNull(ghost);
        }
예제 #2
0
        public void CleanerGhostArrivalOutside()
        {
            Hotel.Hotel hotel   = new Hotel.Hotel();
            GuestRoom   room    = new GuestRoom(1, new Point(1, 0), new Point(1, 1), 1);
            EmptyRoom   outside = new EmptyRoom(0, new Point(0, 0), new Point(1, 1));

            outside.Entrance = true;
            hotel.Rooms.Add(room);
            hotel.Rooms.Add(outside);

            room.Neighbors.Add(Direction.West, room);
            outside.Neighbors.Add(Direction.East, room);

            CleanerGhost ghost = new CleanerGhost(outside);

            ghost.RemoveObjectEvent += hotel.RemoveObject;
            hotel.Staff.Add(ghost);

            hotel.Update(1);
            ghost.OnArrival();
            hotel.Update(1);

            Assert.IsTrue(hotel.Staff[0] is Cleaner);
        }
예제 #3
0
        /// <summary>
        /// Remove a object.
        /// </summary>
        /// <param name="object">The object to remove.</param>
        public void RemoveObject(object sender, EventArgs e)
        {
            HotelObject hotelObject = (HotelObject)sender;

            if (hotelObject is Person)
            {
                // Remove guest from the hotel.
                if (hotelObject is Guest)
                {
                    string item  = Guests.First(x => x.Value == hotelObject).Key;
                    Guest  guest = (Guest)hotelObject;

                    if (guest.Room != null)
                    {
                        if (guest.Room.State != RoomState.Emergency && guest.Room.State != RoomState.InCleaning)
                        {
                            guest.Room.State = RoomState.Dirty;
                        }
                        guest.Room = null;
                    }

                    //Remove the guest from a checkin/out queue where applicable.
                    if (guest.CurrentRoom is Lobby)
                    {
                        (guest.CurrentRoom as Lobby).RemoveFromQueues(guest);
                    }

                    Guests.Remove(item);
                }
                // Remove receptionist from hotel.
                else if (hotelObject is Receptionist)
                {
                    Lobby lobby = Rooms.Where(x => x is Lobby && (x as Lobby).Receptionist == hotelObject) as Lobby;
                    if (lobby != null)
                    {
                        lobby.Receptionist = null;
                    }
                    Staff.Remove(hotelObject as Person);
                }
                // Remove cleaner from the hotel.
                else if (hotelObject is Cleaner)
                {
                    Cleaner cleaner = (Cleaner)hotelObject;
                    Staff.Remove(cleaner);

                    // Spawn a ghost
                    CleanerGhost cGhost = new CleanerGhost(cleaner.CurrentRoom);
                    cGhost.RemoveObjectEvent += RemoveObject;
                    Staff.Add(cGhost);
                }
                else if (hotelObject is CleanerGhost)
                {
                    CleanerGhost cleanerGhost = (CleanerGhost)hotelObject;

                    // Spawn a new cleaner
                    Cleaner cleaner = new Cleaner(cleanerGhost.CurrentRoom);
                    cleaner.RemoveObjectEvent += RemoveObject;
                    Staff.Add(cleaner);
                    // Make it walk indoors
                    cleaner.FindAndTargetRoom(x => (x is Lobby && (x as Lobby).Receptionist != null));

                    Staff.Remove(cleanerGhost);
                }

                hotelObject.RemoveObjectEvent -= RemoveObject;
            }
        }