Ejemplo n.º 1
0
        public void SelectNearestAnimalByTypeCarnivore_should_return_point_with_position_of_nearby_carnivore()
        {
            //Arrange
            Point expectedResult = new Point(2, 0);

            _field.Object.Animals[0, 0].VisionRange = 5;

            //Act
            _result = _systemUnderTest.SelectNearestAnimalByType(_position, AnimalType.Carnivore);

            //Assert
            Assert.AreEqual(expectedResult, _result);
        }
Ejemplo n.º 2
0
        public void MoveAnimals(AnimalType type)
        {
            MovedAnimals = new List <Point>();

            for (int i = 0; i < _field.Heigth; i++)
            {
                for (int j = 0; j < _field.Width; j++)
                {
                    IAnimal animal = _field.Animals[i, j];

                    if ((animal != null) && (animal.Type == type))
                    {
                        Point oldPosition = new Point(j, i);
                        Point newPosition;
                        Point nearestHerbivore = _animalFinder.SelectNearestAnimalByType(oldPosition, AnimalType.Herbivore);
                        Point nearestCarnivore = _animalFinder.SelectNearestAnimalByType(oldPosition, AnimalType.Carnivore);;

                        if (animal.Type == AnimalType.Carnivore)
                        {
                            newPosition = _positionHandler.GetNewPositionByBehavior(animal, nearestHerbivore, oldPosition, MovingType.Pursuit);
                            if (((_field.Animals[newPosition.Y, newPosition.X] != null) && (_field.Animals[newPosition.Y, newPosition.X].Type == AnimalType.Herbivore)))
                            {
                                _healthHandler.IncreaseHealth(animal, 10);
                            }
                        }
                        else
                        {
                            newPosition = _positionHandler.GetNewPositionByBehavior(animal, nearestCarnivore, oldPosition, MovingType.Runaway);
                        }
                        if (!MovedAnimals.Contains(oldPosition))
                        {
                            _pointReplacer.ReplacePoint(oldPosition, newPosition);
                            MovedAnimals.Add(newPosition);
                        }
                    }
                }
            }
        }