Exemplo n.º 1
0
 private void RamoveCurrentWall(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;
         }
     }
 }
Exemplo n.º 2
0
        private 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 < _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)];
                    RamoveCurrentWall(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);
        }