Exemple #1
0
 private 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, current.Col].Value = 0;
         }
         else
         {
             M[selected.Row - 1, selected.Col].Value = 0;
         }
     }
 }
Exemple #2
0
        private static void RemoveWall(ref genCell[,] M)
        {
            genCell current = M[1, 1];

            current.Visited = true;

            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 < rowsS - 3 && !M[row + 2, col].Visited)
                {
                    cells.Add(M[row + 2, col]);
                }
                if (col < columnsS - 3 && !M[row, col + 2].Visited)
                {
                    cells.Add(M[row, col + 2]);
                }

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

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