Example #1
0
        public TempAnimal FindDistance(TempAnimal animal, int[] myPosition)
        {
            int DistanceHeight = Math.Abs(myPosition[0] - animal.heightPos);
            int DistanceWidth  = Math.Abs(myPosition[1] - animal.widthPos);

            int shortestWay = (int)Math.Round(Math.Sqrt(DistanceHeight * DistanceHeight + DistanceWidth * DistanceWidth));

            animal.Distance = shortestWay;
            return(animal);
        }
Example #2
0
        public void WatchAround(IAnimal[,] gameField)
        {
            int rowLimit    = gameField.GetLength(0);
            int columnLimit = gameField.GetLength(1);

            foreach (IAnimal animal in gameField)
            {
                if (animal != null)
                {
                    int FOV      = animal.FieldOfView;
                    int myHeight = animal.Position[0];
                    int myWidth  = animal.Position[1];

                    for (int heightPos = myHeight - FOV; heightPos + FOV < rowLimit - 1; heightPos++)
                    {
                        for (int widthPos = myWidth - FOV; widthPos + FOV < columnLimit - 1; widthPos++)
                        {
                            if (!(heightPos < 0 || widthPos < 0) &&
                                gameField[heightPos, widthPos] != null)
                            {
                                if (gameField[heightPos, widthPos] is Predator)
                                {
                                    TempAnimal predator   = new TempAnimal(heightPos, widthPos);
                                    int[]      myPosition = new int[] { myHeight, myWidth };
                                    Predators.Add(FindDistance(predator, myPosition));
                                    SortByDistance();
                                    Logic.FindNextMove findMove = new Logic.FindNextMove();
                                    findMove.findNextMove(gameField, animal, Predators);
                                }
                                if (gameField[heightPos, widthPos] is Prey)
                                {
                                    TempAnimal prey       = new TempAnimal(heightPos, widthPos);
                                    int[]      myPosition = new int[] { myHeight, myWidth };
                                    Preys.Add(FindDistance(prey, myPosition));
                                    SortByDistance();
                                }
                            }
                        }
                    }
                }
            }
        }