Esempio n. 1
0
File: Zoo.cs Progetto: hebgehogg/Zoo
        private void Animal_DeadEvent(object sender, System.EventArgs e)
        {
            var animal = (Animal)sender;

            animal.DeadEvent -= Animal_DeadEvent;
            if (animal is Predator predator)
            {
                Logger.Info($"The {animal.Name} died");
                Predators.Remove(predator);
                if (animal is Lion lion)
                {
                    Predators.Add(AnimalFactory.GetAnimal <Lion>());
                }
                if (animal is Fox fox)
                {
                    Predators.Add(AnimalFactory.GetAnimal <Fox>());
                }
            }
            if (animal is Herbivore herbivore)
            {
                Logger.Info($"The {animal.Name} died");
                Herbivores.Remove(herbivore);
                if (animal is Goat goat)
                {
                    Herbivores.Add(AnimalFactory.GetAnimal <Goat>());
                }
                if (animal is Ram ram)
                {
                    Herbivores.Add(AnimalFactory.GetAnimal <Ram>());
                }
            }

            Logger.Info("The " + animal.Name + " born");
        }
Esempio n. 2
0
        public void deletePredator()
        {
            var toDelete = Predators.Where(p => p.HitPoints <= 0).ToList();

            foreach (var td in toDelete)
            {
                Predators.Remove(td);
            }
        }