AddFood() public method

public AddFood ( Point currentPoint ) : void
currentPoint System.Drawing.Point
return void
コード例 #1
0
        private void Build(
            bool[,] creaturesMatrix,
            int pointX,
            int pointY,
            FoodMatrix eatMatrix)
        {
            int length = eatMatrix.Length;
            int height = eatMatrix.Height;

            var stack = new Stack<Point>();
            var visitedCells = new bool[length, height];

            stack.Push(new Point(pointX, pointY));

            while (stack.Count != 0)
            {
                var current = stack.Pop();
                visitedCells[current.X, current.Y] = true;

                if (CommonMethods.IsValid(current, length, height)
                    && !creaturesMatrix[current.X, current.Y])
                {
                    if (!eatMatrix.HasMaxFoodLevel(current))
                        eatMatrix.AddFood(current);

                    foreach (var point in CommonMethods.GetPoints(current))
                    {
                        if(CommonMethods.IsValid(point, length, height) && !visitedCells[point.X, point.Y])
                            stack.Push(point);
                    }
                }
            }
        }
コード例 #2
0
        public static void RaiseFoodLevelToConstantWithAddFood(FoodMatrix eatMatrix, Point point, int constant)
        {
            var counter = 0;

            while (counter < constant)
            {
                eatMatrix.AddFood(point);
                counter += FoodMatrixConstants.AddedFoodLevel;
            }
        }
コード例 #3
0
 public void Build(bool[,] creatures, FoodMatrix eatMatrix)
 {
     for (int i = 0; i < eatMatrix.Length; i++)
     {
         for (int j = 0; j < eatMatrix.Height; j++)
         {
             if (!creatures[i, j] &&
                 !eatMatrix.HasMaxFoodLevel(new Point(i, j)) &&
                 _random.Next(100) % _frequency == 0)
             {
                 eatMatrix.AddFood(new Point(i, j));
             }
         }
     }
 }
コード例 #4
0
 public void Build(bool[,] creatures, FoodMatrix eatMatrix)
 {
     for (int i = 0; i < eatMatrix.Length; i++)
     {
         for (int j = 0; j < eatMatrix.Height; j++)
         {
             if (!creatures[i, j]
                 && !eatMatrix.HasMaxFoodLevel(new Point(i, j))
                 && _random.Next(100) % _frequency == 0)
             {
                 eatMatrix.AddFood(new Point(i, j));
             }
         }
     }
 }
コード例 #5
0
        public void Build(bool[,] creatures, FoodMatrix eatMatrix)
        {
            _counterOfTurns++;

            if(_counterOfTurns % _frequency != 0)
                return;

            for (int i = 0; i < eatMatrix.Length; i++)
            {
                for (int j = 0; j < eatMatrix.Height; j++)
                {
                    if (!creatures[i, j]
                        && !eatMatrix.HasMaxFoodLevel(new Point(i, j)))
                    {
                        eatMatrix.AddFood(new Point(i, j));
                    }
                }
            }
        }
コード例 #6
0
        public void Build(bool[,] creatures, FoodMatrix eatMatrix)
        {
            _counterOfTurns++;

            if (_counterOfTurns % _frequency != 0)
            {
                return;
            }

            for (int i = 0; i < eatMatrix.Length; i++)
            {
                for (int j = 0; j < eatMatrix.Height; j++)
                {
                    if (!creatures[i, j] &&
                        !eatMatrix.HasMaxFoodLevel(new Point(i, j)))
                    {
                        eatMatrix.AddFood(new Point(i, j));
                    }
                }
            }
        }
コード例 #7
0
        private void Build(
            bool[,] creaturesMatrix,
            int pointX,
            int pointY,
            FoodMatrix eatMatrix)
        {
            int length = eatMatrix.Length;
            int height = eatMatrix.Height;

            var stack        = new Stack <Point>();
            var visitedCells = new bool[length, height];

            stack.Push(new Point(pointX, pointY));

            while (stack.Count != 0)
            {
                var current = stack.Pop();
                visitedCells[current.X, current.Y] = true;

                if (CommonMethods.IsValid(current, length, height) &&
                    !creaturesMatrix[current.X, current.Y])
                {
                    if (!eatMatrix.HasMaxFoodLevel(current))
                    {
                        eatMatrix.AddFood(current);
                    }

                    foreach (var point in CommonMethods.GetPoints(current))
                    {
                        if (CommonMethods.IsValid(point, length, height) && !visitedCells[point.X, point.Y])
                        {
                            stack.Push(point);
                        }
                    }
                }
            }
        }