Exemple #1
0
        private int[] Approach(IAnimal prey, IAnimal me)
        {
            int myHeight       = me.Position[0];
            int myWidth        = me.Position[1];
            int approachHeight = prey.Position[0];
            int approachWidth  = prey.Position[1];

            int[] nextPosition = new int[2];

            FindNextMove find = new FindNextMove();

            nextPosition[0] = find.ApproachAnimal(approachHeight, myHeight, 26, 1);
            nextPosition[1] = find.ApproachAnimal(approachWidth, myWidth, 26, 1);

            return(nextPosition);
        }
Exemple #2
0
        private int[] Avoid(IAnimal predator, IAnimal me)
        {
            int myHeight    = me.Position[0];
            int myWidth     = me.Position[1];
            int avoidHeight = predator.Position[0];
            int avoidWidth  = predator.Position[1];

            int[] nextPosition = new int[2];

            FindNextMove find = new FindNextMove();

            nextPosition[0] = find.AvoidAnimal(avoidHeight, myHeight, 26, 1);
            nextPosition[1] = find.AvoidAnimal(avoidWidth, myWidth, 26, 1);

            return(nextPosition);
        }
Exemple #3
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();
                                }
                            }
                        }
                    }
                }
            }
        }