Exemplo n.º 1
0
        public void PopulateMaze(AbstractRuleGenerator.RandomNext nextminmax)
        {
            var cellStack = new Stack <MazeCell>();
            var x         = nextminmax(0, 6);
            var y         = nextminmax(0, 6);
            var cell      = GetCell(x, y);

            VisitCell(cell, cellStack, nextminmax);
        }
Exemplo n.º 2
0
 public void VisitCell(MazeCell cell, Stack <MazeCell> cellStack, AbstractRuleGenerator.RandomNext nextminmax)
 {
     while (cell != null)
     {
         cell.Visited = true;
         var mazeCell = GetNextNeigbour(cell, nextminmax);
         if (mazeCell != null)
         {
             MazeCell.RemoveWalls(cell, mazeCell);
             cellStack.Push(cell);
         }
         else if (cellStack.Count > 0)
         {
             mazeCell = cellStack.Pop();
         }
         cell = mazeCell;
     }
 }
Exemplo n.º 3
0
 public void BuildMaze(AbstractRuleGenerator.RandomNext nextminmax)
 {
     for (var i = 0; i < 6; i++)
     {
         for (var j = 0; j < 6; j++)
         {
             if (i > 0)
             {
                 nextminmax();
             }
             if (j > 0)
             {
                 nextminmax();
             }
         }
     }
     PopulateMaze(nextminmax);
     nextminmax();
     nextminmax();   //Burn the coordinate circles.
 }
Exemplo n.º 4
0
        public MazeCell GetNextNeigbour(MazeCell cell, AbstractRuleGenerator.RandomNext nextminmax)
        {
            var list = new List <MazeCell>();

            if (cell.X > 0 && !CellGrid[cell.X - 1][cell.Y].Visited)
            {
                list.Add(CellGrid[cell.X - 1][cell.Y]);
            }
            if (cell.X < CellGrid.Count - 1 && !CellGrid[cell.X + 1][cell.Y].Visited)
            {
                list.Add(CellGrid[cell.X + 1][cell.Y]);
            }
            if (cell.Y > 0 && !CellGrid[cell.X][cell.Y - 1].Visited)
            {
                list.Add(CellGrid[cell.X][cell.Y - 1]);
            }
            if (cell.Y < CellGrid[cell.X].Count - 1 && !CellGrid[cell.X][cell.Y + 1].Visited)
            {
                list.Add(CellGrid[cell.X][cell.Y + 1]);
            }
            return(list.Count > 0
                ? list[nextminmax(0, list.Count)]
                : null);
        }