示例#1
0
 private bool InBounds(Point startCoords, int figureSize)
 {
     for (int column = startCoords.Y; column < startCoords.Y + figureSize; column++)
     {
         for (int raw = startCoords.X; raw < startCoords.X + figureSize; raw++)
         {
             if (!CurrentGeneration.ContainsKey(new Point(raw, column)))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
示例#2
0
        /// <summary>
        /// Checks square around cell and returns true, if cell is alive.
        /// </summary>
        /// <param name="cellCoord"></param>
        /// <param name="currentGeneration"></param>
        /// <returns></returns>
        private bool CheckCellState(Point cellCoord)
        {
            int livesCounter = 0;

            var neighbours = new Point []
            {
                new Point(cellCoord.X - 1, cellCoord.Y - 1),
                new Point(cellCoord.X, cellCoord.Y - 1),
                new Point(cellCoord.X + 1, cellCoord.Y - 1),
                new Point(cellCoord.X - 1, cellCoord.Y),
                new Point(cellCoord.X + 1, cellCoord.Y),
                new Point(cellCoord.X - 1, cellCoord.Y + 1),
                new Point(cellCoord.X, cellCoord.Y + 1),
                new Point(cellCoord.X + 1, cellCoord.Y + 1),
            };

            foreach (var neighbour in neighbours)
            {
                if (CurrentGeneration.ContainsKey(neighbour) && CurrentGeneration[neighbour].Alive)
                {
                    livesCounter++;
                }
            }

            if ((livesCounter == 3 || livesCounter == 2) && CurrentGeneration[new Point((cellCoord.X + Size) % Size, (cellCoord.Y + Size) % Size)].Alive)
            {
                return(true);
            }
            else if (livesCounter == 3)
            {
                return(true);
            }
            else if (livesCounter < 2 || livesCounter > 3)
            {
                return(false);
            }
            else
            {
                return(false);
            }
        }