示例#1
0
        /// <summary>
        /// Recursive method that floods the cave to discover holes in it, it fills a hole object that was given during the method invocation
        /// </summary>
        /// <param name="hole">The hole that is going to be filled</param>
        private void Flood(ref bool[,] buffer, Bubble hole, int x, int y, bool target)
        {
            //if this cell is valid and it's empty
            if (!(x < 0 || y < 0 || x >= buffer.GetLength(0) || y >= buffer.GetLength(0)) &&
                buffer[x, y] != target)
            {
                //write fill it
                buffer[x, y] = target;

                //add its coordinate to the hole's list
                hole.AddCell(x, y);

                //reverberate to adjacent cells
                Flood(ref buffer, hole, x + 1, y, target);
                Flood(ref buffer, hole, x - 1, y, target);
                Flood(ref buffer, hole, x, y + 1, target);
                Flood(ref buffer, hole, x, y - 1, target);
            }
        }