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 reproducePredator()
        {
            var toRepoduce = Predators.Where(p => p.HitPoints > 150 && p.Satiety > 150).ToList();

            foreach (var tr in toRepoduce)
            {
                Predators.Add(tr);
            }
        }
Beispiel #3
0
        public void deletePredator()
        {
            var toDelete = Predators.Where(p => p.HitPoints <= 0).ToList();

            foreach (var td in toDelete)
            {
                Predators.Remove(td);
            }
        }
        static void Main(string[] args)
        {
            Animal animal = new Animal();

            animal.Description();

            Animal predators = new Predators();

            predators.Description();

            Animal[] animals =
            {
                new Fox(),
                new Wolf(),
                new Fox(),
                new Rabbit()
            };

            int amount  = animal.GetAnimalCount(typeof(Fox), animals);
            int amount2 = animal.GetAnimalsCountByClass(typeof(Predators), animals);
        }
Beispiel #5
0
        private void Update()
        {
            if (Time.time >= _nextSeason)
            {
                _nextSeason = Time.time + SeasonRate;
                int a = Mathf.RoundToInt(Random.Range(0, _soureces.Count - 0.51f));
                int i = 0;
                foreach (List <GameObject> l in _soureces)
                {
                    bool active = Random.value <= SourceChance || a == i;
                    foreach (GameObject plant in l)
                    {
                        plant.SetActive(active);
                    }
                    i++;
                }
            }

            if (!_predators && Predator.MalesAlive + Predator.FemalesAlive < 2)
            {
                Predators.Add(Instantiate(PredatorPrefab, Vector3.zero, Quaternion.identity));
            }

            if (_predators && Time.time >= AppearanceTime)
            {
                _predators = false;
                float aux1 = EnvironmentSize - 2f;
                for (int i = 0; i < PredatorsNum; i++)
                {
                    Vector3 tmp = new Vector3(
                        Random.Range(-aux1, aux1),
                        Random.Range(-aux1, aux1),
                        Random.Range(-aux1, aux1));
                    Predators.Add(Instantiate(PredatorPrefab, tmp, Quaternion.identity));
                }
            }

            if (Time.time >= _nextMating)
            {
                if (_matingSeason)
                {
                    _matingSeason = false;
                    _nextMating  += MatingSeason;
                    foreach (GameObject whale in Predators)
                    {
                        Predator predator = whale.GetComponent <Predator>();
                        if (!predator.IsMale)
                        {
                            predator.Mating = false;
                        }
                    }
                    if (_bestWhale != null)
                    {
                        _bestWhale.SetAlpha(false);
                    }
                }
                else
                {
                    float maxEnergy = 0;
                    foreach (GameObject whale in Predators)
                    {
                        Predator predator = whale.GetComponent <Predator>();
                        if (predator.IsMale && predator.Energy > maxEnergy)
                        {
                            maxEnergy  = predator.Energy;
                            _bestWhale = predator;
                        }
                    }

                    if (_bestWhale != null)
                    {
                        foreach (GameObject whale in Predators)
                        {
                            Predator predator = whale.GetComponent <Predator>();
                            if (!predator.IsMale)
                            {
                                predator.Mate(_bestWhale.gameObject);
                            }
                        }
                        _bestWhale.SetAlpha(true);
                        _bestWhale.Energy /= 2;
                        _matingSeason      = true;
                        _nextMating       += MatingDuration;
                    }
                    else
                    {
                        _nextMating += MatingSeason;
                    }
                }
            }
        }