예제 #1
0
        /// <summary>
        /// The guest feeds an animal.
        /// </summary>
        /// <param name="sender">System data.</param>
        /// <param name="e">Associated event data.</param>
        private void feedAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            // Find a guest to feed the animal.
            Guest guest = guestListBox.SelectedItem as Guest;

            // Find an animal to feed.
            Animal animal = animalListBox.SelectedItem as Animal;

            if (guest != null && animal != null)
            {
                // Feed the selected animal.
                guest.FeedAnimal(animal, this.comoZoo.AnimalSnackMachine);

                PopulateAnimalListBox();
                PopulateGuestListBox();
            }
            else
            {
                MessageBox.Show("Please choose both a guest and an animal.");
            }

            // Keep both selections active.
            guest  = guestListBox.SelectedItem as Guest;
            animal = animalListBox.SelectedItem as Animal;
        }
예제 #2
0
        /// <summary>
        /// Has the guest feed an animal.
        /// </summary>
        /// <param name="sender">The object that initiated the event.</param>
        /// <param name="e">The event arguments of the event.</param>
        private void feedAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Guest guest = this.guestListBox.SelectedItem as Guest;

                Animal animal = this.animalListBox.SelectedItem as Animal;

                if (guest != null && animal != null)
                {
                    guest.FeedAnimal(animal);
                }
                else
                {
                    MessageBox.Show("You must choose a guest and an animal to feed an animal.");
                }

                this.guestListBox.SelectedItem  = guest;
                this.animalListBox.SelectedItem = animal;
            }
            catch
            {
                MessageBox.Show("You must create a zoo before feeding animals.");
            }
        }
예제 #3
0
        /// <summary>
        /// The button to feed the animal.
        /// </summary>
        /// <param name="sender"> Not available.</param>
        /// <param name="e"> The parameter is not used.</param>
        private void feedAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            // Greg feeds the ostrich.
            Guest  greg    = this.comoZoo.FindGuest("Greg");
            Animal ostrich = this.comoZoo.FindAnimal(typeof(Ostrich));

            greg.FeedAnimal(ostrich, this.comoZoo.AnimalSnackMachine);
        }
예제 #4
0
        /// <summary>
        /// Requests that Sally feed a dingo.
        /// </summary>
        /// <param name="sender">The object that initiated the event.</param>
        /// <param name="e">The event arguments for the event.</param>
        private void sallyFeedDingoButton_Click(object sender, RoutedEventArgs e)
        {
            // Get the beginning total animal weight.
            double beginningWeight = this.comoZoo.TotalAnimalWeight;

            // Find Sally.
            Guest sally = this.comoZoo.FindGuest("Sally");

            // Find a dingo.
            Animal dingo = this.comoZoo.FindAnimal(GetType());

            // Call guest.FeedAnimal.
            sally.FeedAnimal(dingo, this.comoZoo.AnimalSnackMachine);

            // Get the ending total animal weight.
            double endingWeight = this.comoZoo.TotalAnimalWeight;
        }
예제 #5
0
        /// <summary>
        /// Requests that Fred feed a platypus.
        /// </summary>
        /// <param name="sender">The object that initiated the event.</param>
        /// <param name="e">The event arguments for the event.</param>
        private void fredFeedPlatypusButton_Click(object sender, RoutedEventArgs e)
        {
            // Get the beginning total animal weight.
            double beginningWeight = this.comoZoo.TotalAnimalWeight;

            // Find Fred.
            Guest fred = this.comoZoo.FindGuest("Fred");

            // Find a platypus.
            Animal platypus = this.comoZoo.FindAnimal(GetType());

            // Call guest.FeedAnimal.
            fred.FeedAnimal(platypus, this.comoZoo.AnimalSnackMachine);

            // Get the ending total animal weight.
            double endingWeight = this.comoZoo.TotalAnimalWeight;
        }
예제 #6
0
        /// <summary>
        /// The button to feed the animal.
        /// </summary>
        /// <param name="sender"> Not available.</param>
        /// <param name="e"> The parameter is not used.</param>
        private void feedAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            // Greg feeds the ostrich.
            //Guest greg = this.zoo.FindGuest("Greg");
            //Animal ostrich = this.zoo.FindAnimal(typeof(Ostrich));

            Guest guest = (Guest)this.guestListBox.SelectedItem;

            Animal animal = (Animal)this.animalListBox.SelectedItem;

            if (guest != null && animal != null)
            {
                guest.FeedAnimal(animal, this.zoo.AnimalSnackMachine);

                PopulateAnimalListBox();
                PopulateGuestListBox();
            }
            else
            {
                MessageBox.Show("You must choose both a guest and an animal to feed an animal.");
            }
            guestListBox.SelectedItem  = guest;
            animalListBox.SelectedItem = animal;
        }