Exemplo n.º 1
0
        /// <summary>
        /// Feeds the specified animal.
        /// </summary>
        /// <param name="animal">The animal to feed.</param>
        /// <param name="animalSnackMachine">The vending machine from which to buy animal food.</param>
        public void FeedAnimal(Animal animal, VendingMachine animalSnackMachine)
        {
            // Define a variable to store the food price.
            decimal foodPrice;

            // Set food price.
            foodPrice = animalSnackMachine.LookupFoodPrice(typeof(Animal));

            // Define a variable to store the payment.
            decimal cashInHand;

            // Set cash in hand.
            cashInHand = this.Wallet.RemoveMoney(foodPrice);

            if (foodPrice == cashInHand)
            {
                // Define variable to store the food.
                Food food = null;

                if (animal.GetType() == typeof(Dingo))
                {
                    // Buy dingo food.
                    food = animalSnackMachine.BuyDingoFood(cashInHand);
                }

                if (animal.GetType() == typeof(Platypus))
                {
                    // Buy platypus food.
                    food = animalSnackMachine.BuyPlatypusFood(cashInHand);
                }

                // Feed the animal.
                animal.Eat(food);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the guest to adopt an animal.
        /// </summary>
        /// <param name="sender">System data.</param>
        /// <param name="e">Associated event data.</param>
        private void adoptAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            // Get the selected guest in the list box.
            Guest guest = this.guestListBox.SelectedItem as Guest;

            // Get the selected animal in the list box.
            Animal animal = this.animalListBox.SelectedItem as Animal;

            if (guest != null && animal != null)
            {
                // Set the animal to the guest's adopted animal.
                guest.AdoptedAnimal = animal;

                // Find the animal's cage and add the guest to it.
                Cage cage = comoZoo.FindCage(animal.GetType());
                cage.Add(guest);

                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;
        }
        /// <summary>
        /// Has the specified guest adopt the specified animal.
        /// </summary>
        /// <param name="sender">The object that initiated the event.</param>
        /// <param name="e">The arguments of the event.</param>
        private void adoptAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            Animal animal = this.animalListBox.SelectedItem as Animal;

            Guest guest = this.comoZoo.FindGuest(g => g.AdoptedAnimal == null);

            if (guest.AdoptedAnimal == null)
            {
                if (animal != null && guest != null)
                {
                    guest.AdoptedAnimal = animal;

                    Cage cage = this.comoZoo.FindCage(animal.GetType());

                    cage.Add(guest);
                }
                else
                {
                    MessageBox.Show("Select a guest and an animal for that guest to adopt.");
                }
            }
            else
            {
                MessageBox.Show("A guest is only allowed to adopt one animal, you can unadopt and re-adopt a different animal.");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Launches the cage window.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void showCageButton_Click(object sender, RoutedEventArgs e)
        {
            // Gets the animal from the animal list box.
            Animal animal = (Animal)animalListBox.SelectedItem;

            // Find the cage based on the animal's type.
            Cage cage = zoo.FindCage(animal.GetType());

            // If an animal was selected, create a new cage window and put the animal in the cage.
            if (animal != null)
            {
                CageWindow cageWindow = new CageWindow(cage);


                cageWindow.Show();
                //if (cageWindow.ShowDialog() == true)
                //{
                //}
            }
            // Ask user to select an animal.
            else
            {
                MessageBox.Show("Please select an aniaml to put in the cage.");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adopts 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 adoptAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            Guest  guest  = this.comoZoo.FindGuest(g => g.AdoptedAnimal != null);
            Animal animal = this.animalListBox.SelectedItem as Animal;

            guest.AdoptedAnimal = animal;
            Cage cage = this.comoZoo.FindCage(animal.GetType());

            cage.Add(guest);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Shows the animal cage.
        /// </summary>
        /// <param name="sender">The object that initiated the event.</param>
        /// <param name="e">The event arguments of the event.</param>
        private void showCageButton_Click(object sender, RoutedEventArgs e)
        {
            Animal animal = this.animalListBox.SelectedItem as Animal;

            if (animal != null)
            {
                CageWindow window = new CageWindow
                                    (
                    this.comoZoo.FindCage(animal.GetType())
                                    );

                window.Show();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Feeds the specified animal.
        /// </summary>
        /// <param name="animal">The animal to feed.</param>
        /// <param name="animalSnackMachine">The vending machine from which to buy animal food.</param>
        public void FeedAnimal(Animal animal, VendingMachine animalSnackMachine)
        {
            // Define a variable to store the food price.
            decimal foodPrice;

            // Set food price.
            foodPrice = animalSnackMachine.LookupFoodPrice(GetType());

            // Define a variable to store the payment.
            decimal cashInHand;

            // Set cash in hand.
            cashInHand = this.Wallet.RemoveMoney(foodPrice);

            if (foodPrice == cashInHand)
            {
                // Define variable to store the food.
                Food food = null;

                // TODO: Below here is the changes that I made and text to Cole about.
                if (animal.GetType() == GetType())
                {
                    // Buy dingo food.
                    food = animalSnackMachine.BuyDingoFood(cashInHand);
                }

                if (animal.GetType() == GetType())
                {
                    // Buy platypus food.
                    food = animalSnackMachine.BuyPlatypusFood(cashInHand);
                }

                // Feed the animal.
                animal.Eat(food);
            }
        }
        /// <summary>
        /// Shows the cage of the specified animal.
        /// </summary>
        /// <param name="sender">The object that initiated the event.</param>
        /// <param name="e">The arguments of the event.</param>
        private void showCageButton_Click(object sender, RoutedEventArgs e)
        {
            Animal animal = this.animalListBox.SelectedItem as Animal;

            if (animal != null)
            {
                Cage cage = this.comoZoo.FindCage(animal.GetType());

                CageWindow window = new CageWindow(cage);

                window.Show();
            }
            else
            {
                MessageBox.Show("Select an animal whose cage to show.");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Shows the cage window.
        /// </summary>
        /// <param name="sender">System data.</param>
        /// <param name="e">Associated event data.</param>
        private void showCageButton_Click(object sender, RoutedEventArgs e)
        {
            // Get the animal selected in the list box.
            Animal animal = this.animalListBox.SelectedItem as Animal;

            if (animal != null)
            {
                // Get the cage of the animal selected.
                Cage cageResult = comoZoo.FindCage(animal.GetType());

                CageWindow cageWindow = new CageWindow(cageResult);
                cageWindow.Show();
            }
            else
            {
                MessageBox.Show("You must select an animal to show.");
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// The button used to adopt an animal.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void adoptAnimalButton_Click(object sender, RoutedEventArgs e)
        {
            // Gets the guest from the list box.
            Guest guest = (Guest)this.guestListBox.SelectedItem;

            // Gets the animal from the list box.
            Animal animal = (Animal)this.animalListBox.SelectedItem;

            // Set the animal to guest's adopted animal.
            guest.AdoptedAnimal = animal;

            // Find the animals cage.
            Cage animalCage = zoo.FindCage(animal.GetType());

            // Add the guest to the cage.
            animalCage.Add(guest);

            // Load the guest into the list box.
            this.PopulateGuestListBox();
        }