Пример #1
0
 public static void RemoveCurrentWall(ref genCell[,] M, genCell current, genCell selected)
 {
     if (current.Row == selected.Row)
     {
         if (current.Col > selected.Col)
         {
             M[current.Row, current.Col - 1].Value = 0;
         }
         else
         {
             M[current.Row, selected.Col - 1].Value = 0;
         }
     }
     else
     {
         if (current.Row > selected.Row)
         {
             M[current.Row - 1, selected.Col].Value = 0;
         }
         else
         {
             M[selected.Row - 1, selected.Col].Value = 0;
         }
     }
 }
Пример #2
0
        public static void RemoveWall(ref genCell[,] M)
        {
            genCell current = M[1, 1];

            current.Visited = false;

            Stack <genCell> stack = new Stack <genCell>();

            do
            {
                List <genCell> cells = new List <genCell>();
                int            row   = current.Row;
                int            col   = current.Col;

                if ((row - 1) > 0 && !M[row - 2, col].Visited)
                {
                    cells.Add(M[row - 2, col]);
                }
                if ((col - 1) > 0 && !M[row, col - 2].Visited)
                {
                    cells.Add(M[row, col - 2]);
                }

                if (row < (Rows - 3) && !M[row + 2, col].Visited)
                {
                    cells.Add(M[row + 2, col]);
                }
                if (col < (Columns - 3) && !M[row, col + 2].Visited)
                {
                    cells.Add(M[row, col + 2]);
                }

                if (cells.Count > 0)
                {
                    genCell selected = cells[rand.Next(cells.Count)];
                    RemoveCurrentWall(ref M, current, selected);

                    selected.Visited = true;
                    M[selected.Row, selected.Col].Value   = 0;
                    M[selected.Row, selected.Col].Visited = true;
                    stack.Push(selected);
                    current = selected;
                }
                else
                {
                    current = stack.Pop();
                }
            } while (stack.Count > 0);
        }