예제 #1
0
파일: Zoo.cs 프로젝트: mtaylorhayden/OOP
        /// <summary>
        /// Removes the animal from the zoo.
        /// </summary>
        /// <param name="animal"> The animal being removed from the zoo.</param>
        public void RemoveAnimal(Animal animal)
        {
            // Loop through the zoo's list of guests.
            foreach (Guest g in this.guests)
            {
                // If any of the guests in the list of guests have adpoted then animal which is being removed...
                if (g.AdoptedAnimal == animal)
                {
                    // Remove the animal from the guest.
                    g.AdoptedAnimal = null;

                    // Remove the guest from the cage.
                    Cage newCage = this.FindCage(animal.GetType());
                    newCage.Remove(g);
                }
            }

            // Remove the animal from the list of animals.
            this.animals.Remove(animal);

            // Find the animals cage and give the cage the type of animal being put into the cage.
            Cage cage = this.FindCage(animal.GetType());

            // Removes the animal from the cage.
            cage.Remove(animal);
        }
예제 #2
0
        /// <summary>
        /// Removes an animal from the zoo.
        /// </summary>
        /// <param name="animal">The animal to remove.</param>
        public void RemoveAnimal(Animal animal)
        {
            animal.IsActive = false;

            this.animals.Remove(animal);
            Cage cage = this.FindCage(animal.GetType());

            cage.Remove(animal);
        }
예제 #3
0
        /// <summary>
        /// Removes an animal from the list of animals in the zoo.
        /// </summary>
        /// <param name="animal">The animal to remove.</param>
        public void RemoveAnimal(Animal animal)
        {
            Guest guest = null;

            // Find the animal's cage.
            Cage cage = this.FindCage(animal.GetType());

            foreach (Guest g in this.Guests)
            {
                guest = g;

                if (guest.AdoptedAnimal == animal)
                {
                    guest.AdoptedAnimal = null;
                    cage.Remove(guest);
                }
            }

            // Remove the animal from the zoo list.
            this.animals.Remove(animal);

            // Remove animal from the cage.
            cage.Remove(animal);
        }
예제 #4
0
        /// <summary>
        /// Removes a guest from the zoo.
        /// </summary>
        /// <param name="guest">The guest to remove.</param>
        public void RemoveGuest(Guest guest)
        {
            this.guests.Remove(guest);

            guest.IsActive = false;

            if (guest.AdoptedAnimal != null)
            {
                Cage cage = this.FindCage(guest.AdoptedAnimal.GetType());

                cage.Remove(guest);
            }

            if (this.OnRemoveGuest == null)
            {
                this.OnRemoveGuest(guest);
            }
        }