Beispiel #1
0
        public void FemaleLionsDoStuff(Lion lion)
        {
            int x = 0;
            int z = lion.location;

            while (Initialize.SavannaGrid[exec.MoveLion(rnd.Next(1, 9), lion.location)].lionCheck() == true && x != z)
            {
                x = exec.MoveLion(rnd.Next(1, 9), lion.location);
            }
            lion.location = x;
            Initialize.SavannaGrid[x].addLionToField();
            lion.weight = lion.weight - 10;

            if (chk.CheckForLionMateForFemale(x) == true)
            {
                //inst.AddLion();
                inst.AddLion();
            }
            if (food.checkForLionFood(x) == true)
            {
                lion.weight = lion.weight + 20;
                foreach (var rabbit in Initialize.RabbitList.ToList())
                {
                    if (rabbit.location == lion.location)
                    {
                        Initialize.RabbitList.Remove(rabbit);
                    }
                }
            }

            Console.WriteLine(lion.weight);
            Console.WriteLine(lion.genderMaleIfTrue);
            Console.WriteLine(lion.location);
            Console.WriteLine(" ");
        }
 public void Setup() {
     lion = new Lion();
     lionActions = new LionActions();
     gameplay = new Gameplay {
         Animals = new List<IAnimal>()
     };
 }
Beispiel #3
0
 public bool TryToEat(List<IAnimal> animals, Lion lion)
 {
     IAnimal antilopeToEat = SearchForAntilope(animals, lion);
     if (antilopeToEat == null)
     {
         return false;
     }
     Eat(antilopeToEat, lion);
     return true;
 }
Beispiel #4
0
 private void AddLionsOnDifferentLocations(List<IAnimal> animals) {
     var lion = new Lion {
         HitPoints = 100,
         Name = "Lion",
         PositionOnXAxis = 2,
         PositionOnYAxis = 2
     };
     var lion2 = new Lion {
         HitPoints = 100,
         Name = "Lion",
         PositionOnXAxis = 3,
         PositionOnYAxis = 3
     };
     animals.Add(lion);
     animals.Add(lion2);
 }
 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));
 }
 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);
 }
Beispiel #7
0
        public void AddLion()
        {
            int  x      = rnd.Next(1, 3);
            bool z      = false;
            int  weight = 300;

            if (x == 1)
            {
                z = true;
            }
            int tryLocation = rnd.Next(0, 400);

            while (SavannaGrid[tryLocation].lionCheck() == true || SavannaGrid[tryLocation].rabbitCheck() == true)
            {
                tryLocation = rnd.Next(0, 400);
            }

            Lion L = new Lion(z, weight, tryLocation);

            SavannaGrid[tryLocation].maleIfTrue = z;
            LionList.Add(L);
        }
Beispiel #8
0
 private IAnimal SearchForAntilope(List<IAnimal> animals, Lion lion)
 {
     IEnumerable<IAnimal> animalsAround = animalActions.LookAround(animals, lion);
     return animalsAround.Where(a => a.HitPoints > 0).FirstOrDefault(a => a.Name == "Antilope");
 }
Beispiel #9
0
 private void MoveToAntilopesPosition(IAnimal antilopeInRange, Lion lion)
 {
     lion.PositionOnXAxis = antilopeInRange.PositionOnXAxis;
     lion.PositionOnYAxis = antilopeInRange.PositionOnYAxis;
 }
Beispiel #10
0
 private void Eat(IAnimal antilope, Lion lion)
 {
     MoveToAntilopesPosition(antilope, lion);
     lion.HitPoints = 100;
     antilope.HitPoints = 0;
 }
Beispiel #11
0
        /// <summary>
        /// Adds a new animal to list based on user input.
        /// Prints it on a random position on gameboard.
        /// </summary>
        /// <param name="input"> user inputs L or A </param>
        private Animal CreateAnimal(string input)
        {
            //Lion lion = new Lion();
            //Antelope antelope = new Antelope();
            Animal animal = null;

            ////Animal animal = new Animal();

            while (animalList.Animals.Count < 120)
            {
                int   xPosition      = random.Next(0, 98);
                int   yPosition      = random.Next(4, 28);
                int[] randomPosition = new int[] { xPosition, yPosition };
                bool  spotIsTaken    = false;

                for (int sizeY = -2; sizeY < 3; sizeY++)
                {
                    for (int sizeX = -2; sizeX < 3; sizeX++)
                    {
                        if (animalList.Animals.Where(a => a.Position[0] + sizeX == xPosition && a.Position[1] + sizeY == yPosition).Any())
                        {
                            spotIsTaken = true;
                        }
                    }
                }
                if (!spotIsTaken)
                {
                    count++;

                    // Adds a Lion to AnimalList and prints it too
                    if (input == "l")
                    {
                        Lion lion = new Lion();
                        lion.Position = new int[2] {
                            xPosition, yPosition
                        };

                        if (animalList.Animals != null)
                        {
                            lion.ID = animalList.Animals.Count + 1;
                        }
                        else
                        {
                            lion.ID = 1;
                        }

                        animalList.Animals.Add(new Lion()
                        {
                            ID              = lion.ID,
                            Trigger         = lion.Trigger,
                            LionRange       = lion.Range,
                            Health          = lion.Health,
                            Position        = lion.Position,
                            IsPredator      = lion.IsPredator,
                            IsMateAvailable = lion.IsMateAvailable,
                        });

                        //uI.PrintAnimal(lion.Position[0], lion.Position[1], lion.Trigger, count);
                        //uI.PrintArray(animalList);
                    }

                    // Adds an Antelope to AnimalList and prints it too
                    else
                    {
                        Antelope antelope = new Antelope();
                        antelope.Position = new int[2] {
                            xPosition, yPosition
                        };

                        if (animalList.Animals != null)
                        {
                            antelope.ID = animalList.Animals.Count + 1;
                        }
                        else
                        {
                            antelope.ID = 1;
                        }

                        animalList.Animals.Add(new Antelope()
                        {
                            ID              = antelope.ID,
                            Trigger         = antelope.Trigger,
                            Range           = antelope.Range,
                            Health          = antelope.Health,
                            Position        = antelope.Position,
                            IsPredator      = antelope.IsPredator,
                            IsMateAvailable = antelope.IsMateAvailable,
                        });
                        //uI.PrintAnimal(antelope.Position[0], antelope.Position[1], antelope.Trigger, count);
                    }

                    break;
                }
            }

            return(animal);
        }
 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);
 }
 private void CreateTwoLions() {
     var newLion = new Lion
     {
         HitPoints = 100,
         Name = "Lion",
         PositionOnXAxis = 4,
         PositionOnYAxis = 4
     };
     var newLion2 = new Lion
     {
         HitPoints = 100,
         Name = "Lion",
         PositionOnXAxis = 5,
         PositionOnYAxis = 5
     };
     gameplay.Animals.Add(newLion);
     gameplay.Animals.Add(newLion2);
 }