Beispiel #1
0
        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");
        }
Beispiel #2
0
        public void reproduceHerbivore()
        {
            var toRepoduce = Herbivores.Where(h => h.HitPoints > 150 && h.Satiety > 150).ToList();

            foreach (var tr in toRepoduce)
            {
                Herbivores.Add(tr);
            }
        }
Beispiel #3
0
        public void BirthCycle()
        {
            List <Herbivore> newbornHerbivores = new List <Herbivore>();
            List <Carnivore> newbornCarnivores = new List <Carnivore>();

            Herbivores = Herbivores.OrderBy(i => i.Fitness).ToList();
            var numHerb = Herbivores.Count();

            foreach (var herb in Herbivores)
            {
                var result = herb.Birth(numHerb);
                if (!(result is null))
                {
                    newbornHerbivores.Add((Herbivore)result);
                }
            }
            foreach (var child in newbornHerbivores)
            {
                Herbivores.Add(child);
            }
            NewHerbivores        = newbornHerbivores.Count();
            TotalHerbivoreLives += newbornHerbivores.Count();

            Carnivores = Carnivores.OrderBy(i => i.Fitness).ToList();
            var numCarn = Carnivores.Count();

            foreach (var carn in Carnivores)
            {
                var result = carn.Birth(numCarn);
                if (!(result is null))
                {
                    newbornCarnivores.Add((Carnivore)result);
                }
            }
            foreach (var child in newbornCarnivores)
            {
                Carnivores.Add(child);
            }
            NewCarnivores        = newbornCarnivores.Count();
            TotalCarnivoreLives += newbornCarnivores.Count();
        }
Beispiel #4
0
 public void Apply(CreateHerbivoreAccepted @event)
 {
     Cells[@event.X, @event.Y] = CellType.Herbivore;
     Herbivores.Add(@event.HerbivoreId, new Herbivore(@event.X, @event.Y, @event.HerbivoreId));
 }