/* * Shark spawn * */ private void SpawnShark(Shark creature) { for (int i = 0; i < _sepiasChildren; i++) { Creature child; child = new Shark(creature.LifeTime, 0, ((Shark)creature).MaxHunger, new Library.Pair()); if (i == 0) { KillCreature(creature.Position.X, creature.Position.Y); child.Position = creature.Position; } else { child.Position = FindPlaceForShark(creature.Position.X, creature.Position.Y); } _simulationField[child.Position.X, child.Position.Y] = child; } }
/* * Initializing the field * */ private void InitializeField(Library.Pair size) { _simulationField = new Creature[size.X, size.Y]; for (int i = 0; i < _sharksCount; i++) { Library.Pair position = FindPlaceForCreature(); Shark shark = new Shark(_sharksLifeTime, 0, _sharksHunger, position); _simulationField[position.X, position.Y] = shark; } for (int i = 0; i < _sepiasCount; i++) { Library.Pair position = FindPlaceForCreature(); Sepia sepia = new Sepia(_sepiasLifeTime, position); _simulationField[position.X, position.Y] = sepia; } }
/* * Moving Shark * */ private void MoveShark(Shark creature, int x, int y) { Library.Pair position = FindPlaceForShark(x, y); if (_simulationField[position.X, position.Y] is Sepia) { KillCreature(position.X, position.Y); creature.Hunger = 0; } _simulationField[x, y] = null; _simulationField[position.X, position.Y] = creature; }
/* * Checking if shark is old enough to have children * */ private bool CheckForSpawnShark(Shark creature) { if (creature.Age == 2 * creature.LifeTime / 3 && creature.Hunger != 0) { SpawnShark(creature); return true; } return false; }