Ejemplo n.º 1
0
Archivo: Zoo.cs Proyecto: 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");
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
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;
                    }
                }
            }
        }