public List <Animal> MoveWithoutEnemies(Animal herbivore, List <Animal> searchList, Field field) { bool foundMove = false; int bestStepX = herbivore.CoordinateX; int bestStepY = herbivore.CoordinateY; while (!foundMove) { int moveX = _facade.GetRandomMinMax(NumParameters.MovingNegative, NumParameters.MovingPositive); int moveY = _facade.GetRandomMinMax(NumParameters.MovingNegative, NumParameters.MovingPositive); int nextStepX = herbivore.CoordinateX + moveX; int nextStepY = herbivore.CoordinateY + moveY; var validMove = _validator.ValidateMove(nextStepX, nextStepY, field) && !_validator.AnimalExists(nextStepX, nextStepY, field); if (validMove) { foundMove = true; bestStepX = nextStepX; bestStepY = nextStepY; } } _genericAnimal.TakeAStep(bestStepX, bestStepY, herbivore, field); return(searchList); }
public Animal CreateAnimal(ConsoleKey key, Field field) { var coordX = _facade.GetRandomMinMax(0, field.Width); var coordY = _facade.GetRandomMinMax(0, field.Height); if (_validator.AnimalExists(coordX, coordY, field)) { CreateAnimal(key, field); } var newAnimal = new Animal(); if (key == TextParameters.AntelopeKey) { newAnimal = new AntelopeLibrary.Antelope(); } else if (key == TextParameters.LionKey) { newAnimal = new LionLibrary.Lion(); } newAnimal.Alive = true; newAnimal.CoordinateX = coordX; newAnimal.CoordinateY = coordY; newAnimal.MatingCount = 0; newAnimal.Health = NumParameters.MaxHealth; field.Animals.Add(newAnimal); return(newAnimal); }
public Animal CreateAnimal(ConsoleKey key, Field field) { var coordX = _facade.GetRandomMinMax(0, field.Width); var coordY = _facade.GetRandomMinMax(0, field.Height); if (_validator.AnimalExists(coordX, coordY, field)) { CreateAnimal(key, field); } var newAnimal = new Animal(); if (key == TextParameters.AntelopeKey) { newAnimal = new Antelope() { Alive = true, CoordinateX = coordX, CoordinateY = coordY, Herbivore = true, Symbol = TextParameters.Antelope, Key = TextParameters.AntelopeKey, MatingCount = 0, Health = NumParameters.MaxHealth, }; } else if (key == TextParameters.LionKey) { newAnimal = new Lion() { Alive = true, CoordinateX = coordX, CoordinateY = coordY, Herbivore = false, Symbol = TextParameters.Lion, Key = TextParameters.LionKey, MatingCount = 0, Health = NumParameters.MaxHealth, }; } field.Animals.Add(newAnimal); return(newAnimal); }