// Constructor public AnimalWorld(ContinentFactory factory) { _carnivore = factory.CreateCarnivore(); _herbivore = factory.CreateHerbivore(); }
// Constructor. public AnimalWorld(ContinentFactory factory) { this.carnivore = factory.CreateCarnivore(); this.herbivore = factory.CreateHerbivore(); }
public void RunRound() { round_count++; Debug.Log(herbies.Count); float current_total_nutrition = 0; float current_minimium_nutrition = 100000; int i_max = world.GetLength(0); int j_max = world.GetLength(1); for (int i = 0; i < i_max; i++) { for (int j = 0; j < j_max; j++) { world[i, j].Reset(); if (round_count % seed_round == seed_round - 1) { SpreadPlants(new Vector2(i, j)); } world[i, j].GrowPlants(); current_total_nutrition += world[i, j].nutrition; if (world[i, j].nutrition > 0 && world[i, j].nutrition < current_minimium_nutrition) { current_minimium_nutrition = world[i, j].nutrition; } } } for (int i = 0; i < herbies.Count; i++) { if (herbies[i].isAlive) { Vector2 best_spot = herbies[i].Search(SliceOfWorld(herbies[i].GetPerceptionRange())); Vector2 new_sprite_location = new Vector2((best_spot.x - world.GetLength(0) / 2) * StaticData.size_increment, (best_spot.y - world.GetLength(1) / 2) * StaticData.size_increment); herbies[i].MoveTo(best_spot, new_sprite_location); } else { GameObject.Destroy(herbies[i].sprite); herbies.RemoveAt(i); i--; } } List <TerrainTile> occupiedTiles = new List <TerrainTile>(); for (int i = 0; i < herbies.Count; i++) { Herbivore herb = herbies[i]; if (!occupiedTiles.Contains(world[(int)herb.location.x, (int)herb.location.y])) { occupiedTiles.Add(world[(int)herb.location.x, (int)herb.location.y]); } herb.Feed(world[(int)herb.location.x, (int)herb.location.y].EatPlants(herb.GetAppetite())); world[(int)herb.location.x, (int)herb.location.y].grazers.Add(herbies[i]); } for (int i = 0; i < carnies.Count; i++) { if (carnies[i].isAlive) { Vector2 best_spot = carnies[i].Search(SliceOfWorld(carnies[i].GetPerceptionRange())); Vector2 new_sprite_location = new Vector2((best_spot.x - world.GetLength(0) / 2) * StaticData.size_increment, (best_spot.y - world.GetLength(1) / 2) * StaticData.size_increment); carnies[i].MoveTo(best_spot, new_sprite_location); } else { GameObject.Destroy(carnies[i].sprite); carnies.RemoveAt(i); i--; } } for (int i = 0; i < carnies.Count; i++) { Carnivore carn = carnies[i]; if (!occupiedTiles.Contains(world[(int)carn.location.x, (int)carn.location.y])) { occupiedTiles.Add(world[(int)carn.location.x, (int)carn.location.y]); } float meal_size = 0; if (carn.SucessfulHunt()) { meal_size = world[(int)carn.location.x, (int)carn.location.y].EatAnimal(); } carn.Eat(meal_size); } for (int i = 0; i < herbies.Count; i++) { int babies = herbies[i].Reproduce(); for (int b = 0; b < babies; b++) { herbies.Add(herbies[i].CreateBaby(transform, sprite_offset)); } } for (int i = 0; i < carnies.Count; i++) { int babies = carnies[i].Reproduce(); for (int b = 0; b < babies; b++) { carnies.Add(carnies[i].CreateBaby(transform, sprite_offset)); } } max_carnivores.FeedValue(carnies.Count); current_carnivores.FeedValue(carnies.Count); max_plants.FeedValue(current_total_nutrition); current_plants.FeedValue(current_total_nutrition); max_herbivores.FeedValue(herbies.Count); current_herbivores.FeedValue(herbies.Count); }
public AnimalWorld(ContinentFactory continent) { _herbivore = continent.CreateHerbivore(); _carnivore = continent.CreateCarnivore(); }
// Constructor public AnimalWorld(ContinentFactory factory) { m_carnivore = factory.CreateCarnivore(); m_herbivore = factory.CreateHerbivore(); }
private Carnivore _carnivore; // создаем переменную типа ХИЩНИК // Constructor public AnimalWorld(ContinentFactory factory) { _carnivore = factory.CreateCarnivore(); // идем на завод и создаем хищника _herbivore = factory.CreateHerbivore(); // идем на завод и создаем травоядное }
// Gets all the animals information as a string. // returns a string with all the animals info for displaying. public override string ToString() { return("Carnivorous: " + Carnivore.ToString() + ", Size: " + AnimalSize.ToString() + ", Points: " + (int)AnimalSize); }
public AnimalWorld(AnimalFactory preHistoricFactory) { _herbivore = preHistoricFactory.CreateHerbivore(); _carnivore = preHistoricFactory.CreateCarnivore(); }
public Animals(ContinentFactory continentFactory) { _herbivore = continentFactory.CreateHerbivore(); _carnivore = continentFactory.CreateCarnivore(); }
public abstract void Eat(Carnivore carnivore);
/// <summary> /// Feed all animals /// </summary> /// <param name="animals">Animals to feed</param> public static void FeedAnimals(Animal[] animals) { int numberOfFoodEntities = 2; Plant[] plantFoodBank = new Plant[numberOfFoodEntities]; for (int i = 0; i < plantFoodBank.Length / 2; i++) { plantFoodBank[i] = new Banana() { Name = "Banana" }; } for (int i = numberOfFoodEntities / 2; i < plantFoodBank.Length; i++) { plantFoodBank[i] = new Bamboo() { Name = "Bamboo" }; } Animal[] meatFoodBank = new Animal[2]; int numberOfFoodForMeatEaters = 0; foreach (Animal animal in animals) { if (animal is Turtle || animal is Monkey) { meatFoodBank[numberOfFoodForMeatEaters] = animal; numberOfFoodForMeatEaters += 1; } } Herbivore[] plantsEaters = new Herbivore[3]; Carnivore[] meatEaters = new Carnivore[2]; int numberOfPlantEaters = 0; int numberOfMeatEaters = 0; foreach (Animal animal in animals) { if (animal is Herbivore) { plantsEaters[numberOfPlantEaters] = (Herbivore)animal; numberOfPlantEaters += 1; } else if (animal is Carnivore) { meatEaters[numberOfMeatEaters] = (Carnivore)animal; numberOfMeatEaters += 1; } } foreach (Herbivore animal in plantsEaters) { foreach (Plant food in plantFoodBank) { animal.NameYourself(); animal.Eat(food); } } foreach (Carnivore animal in meatEaters) { foreach (Animal food in meatFoodBank) { animal.NameYourself(); if (food.FrightLevel < 2) { animal.Scare(food); } animal.Eat(food); } } }