public void SetUp() {
     antilope = new Antilope();
     antilopeActions = new AntilopeActions();
     gameplay = new Gameplay {
         Animals = new List<IAnimal>()
     };
     board = new Board();
     board.Create();
 }
Example #2
0
 public bool TryToRunAway(List<IAnimal> animals, Board board, Antilope antilope)
 {
     IEnumerable<IAnimal> lionsAround = SearchForLions(animals, antilope);
     IEnumerable<IAnimal> enumeratedLionsAround = lionsAround as IList<IAnimal> ?? lionsAround.ToList();
     if (!enumeratedLionsAround.Any())
     {
         return false;
     }
     RunAway(animals, enumeratedLionsAround, board, antilope);
     return true;
 }
Example #3
0
 private bool SpaceIsFree(IEnumerable<IAnimal> animals, int x, int y, Antilope antilope)
 {
     var spaceIsNotTaken = true;
     foreach (IAnimal animal in animals)
     {
         if (IsNotFree(x, y, animal, antilope))
         {
             spaceIsNotTaken = false;
         }
     }
     return spaceIsNotTaken;
 }
Example #4
0
 private bool IsSafePlaceToGo(IEnumerable<IAnimal> lions, int x, int y, Antilope antilope)
 {
     foreach (IAnimal lion in lions)
     {
         if ((Math.Abs(antilope.PositionOnXAxis + x - lion.PositionOnXAxis) > 1) ||
             (Math.Abs(antilope.PositionOnYAxis + y - lion.PositionOnYAxis) > 1))
         {
             continue;
         }
         return false;
     }
     return true;
 }
Example #5
0
 private void RunAway(List<IAnimal> animals, IEnumerable<IAnimal> lionsAround, Board board, Antilope antilope)
 {
     IEnumerable<IAnimal> enumeratedLionsAround = lionsAround as IList<IAnimal> ?? lionsAround.ToList();
     for (int y = -1; y <= 1; y++)
     {
         for (int x = -1; x <= 1; x++)
         {
             if (board.OutOfBounds(x, y, board.Layout, antilope) || !SpaceIsFree(animals, x, y, antilope) ||
                 !IsSafePlaceToGo(enumeratedLionsAround, x, y, antilope))
             {
                 continue;
             }
             MoveTo(x, y, antilope);
             return;
         }
     }
 }
 public void TryToRunAway_RunsAwayFromLion_ReturnsTrue() {
     var newAntilope = new Antilope {
         HitPoints = 150,
         Name = "Antilope",
         PositionOnXAxis = 3,
         PositionOnYAxis = 3
     };
     var newLion = new Lion {
         HitPoints = 100,
         Name = "Lion",
         PositionOnXAxis = 4,
         PositionOnYAxis = 4
     };
     gameplay.Animals.Add(newAntilope);
     gameplay.Animals.Add(newLion);
     Assert.IsTrue(antilopeActions.TryToRunAway(gameplay.Animals, board, newAntilope));
 }
Example #7
0
 public void TryToEat_NotFullHealthLionEatsOneAntilope_ReturnsTrue() {
     var newLion = new Lion {
         HitPoints = 10,
         Name = "Lion",
         PositionOnXAxis = 2,
         PositionOnYAxis = 2
     };
     var antilopeToEat = new Antilope {
         HitPoints = 150,
         Name = "Antilope",
         PositionOnXAxis = 1,
         PositionOnYAxis = 2
     };
     gameplay.Animals.Add(newLion);
     gameplay.Animals.Add(antilopeToEat);
     Assert.IsTrue(lionActions.TryToEat(gameplay.Animals, newLion));
     Assert.AreEqual(100, newLion.HitPoints);
     Assert.AreEqual(0, antilopeToEat.HitPoints);
 }
Example #8
0
 private IEnumerable<IAnimal> SearchForLions(List<IAnimal> animals, Antilope antilope)
 {
     IEnumerable<IAnimal> lionsAround = animalActions.LookAround(animals, antilope);
     return lionsAround.Where(l => l.Name == "Lion");
 }
Example #9
0
 private bool IsNotFree(int x, int y, IAnimal animal, Antilope antilope)
 {
     return antilope.PositionOnXAxis + x == animal.PositionOnXAxis && antilope.PositionOnYAxis + y == animal.PositionOnYAxis;
 }
Example #10
0
 private void MoveTo(int x, int y, Antilope antilope)
 {
     antilope.PositionOnXAxis += x;
     antilope.PositionOnYAxis += y;
 }
 private void CreateTwoAntilopes() {
     var newAntilope = new Antilope
     {
         HitPoints = 150,
         Name = "Antilope",
         PositionOnXAxis = 3,
         PositionOnYAxis = 3
     };
     var newAntilope2 = new Antilope
     {
         HitPoints = 150,
         Name = "Antilope",
         PositionOnXAxis = 5,
         PositionOnYAxis = 5
     };
     gameplay.Animals.Add(newAntilope);
     gameplay.Animals.Add(newAntilope2);
 }
 private void CreateLionsAroundAntilope() {
     var mainAntilope = new Antilope
     {
         HitPoints = 150,
         Name = "Antilope",
         PositionOnXAxis = 5,
         PositionOnYAxis = 5
     };
     var newLion = new Lion
     {
         HitPoints = 100,
         Name = "Lion",
         PositionOnXAxis = 4,
         PositionOnYAxis = 4
     };
     var newLion2 = new Lion
     {
         HitPoints = 100,
         Name = "Lion",
         PositionOnXAxis = 6,
         PositionOnYAxis = 4
     };
     var newLion3 = new Lion
     {
         HitPoints = 100,
         Name = "Lion",
         PositionOnXAxis = 6,
         PositionOnYAxis = 5
     };
     gameplay.Animals.Add(mainAntilope);
     gameplay.Animals.Add(newLion);
     gameplay.Animals.Add(newLion2);
     gameplay.Animals.Add(newLion3);
 }
 private void CreateAntilopeAndLionToEat()
 {
     var newLion = new Lion
     {
         HitPoints = 100,
         Name = "Lion",
         PositionOnXAxis = 4,
         PositionOnYAxis = 4
     };
     var newAntilope = new Antilope
     {
         HitPoints = 150,
         Name = "Antilope",
         PositionOnXAxis = 5,
         PositionOnYAxis = 5
     };
     gameplay.Animals.Add(newLion);
     gameplay.Animals.Add(newAntilope);
 }