Exemplo n.º 1
0
        public Edge(int x, int y, Directions direction, int depth)
        {
            origin = new Cell {direction = direction, x = x, y = y, depth = depth};
            exit = new Cell {x = x, y = y, depth = depth + 1};

            switch (origin.direction)
            {
                case Directions.Left:
                    exit.direction = Directions.Right;
                    exit.x -= 1;
                    break;
                case Directions.Right:
                    exit.direction = Directions.Left;
                    exit.x += 1;
                    break;
                case Directions.Down:
                    exit.direction = Directions.Up;
                    exit.y -= 1;
                    break;
                case Directions.Up:
                    exit.direction = Directions.Down;
                    exit.y += 1;
                    break;
            }
        }
Exemplo n.º 2
0
        public MazeGenerator(int mazeWidth, int mazeHeight, int cellSize, int wallSize, int pauseStep = 200)
        {
            int cellWidth = (mazeWidth - wallSize)/(cellSize + wallSize);
            int cellHeight = (mazeHeight - wallSize)/(cellSize + wallSize);
            maze = new Maze(cellWidth, cellHeight);

            var origin = new Cell
            {
                x = Random.Range(0, cellWidth),
                y = Random.Range(0, cellHeight)
            };
            maze[origin] = Directions.None;
            edges = new List<Edge>(maze.GetEdges(origin));

            this.pauseStep = pauseStep;
        }
Exemplo n.º 3
0
 public List<Edge> GetEdges(Cell origin)
 {
     var edges = new List<Edge>();
     if (origin.direction != Directions.Left)
     {
         var edge = new Edge(origin.x, origin.y, Directions.Right, origin.depth);
         if (Contains(edge.exit) && this[edge.exit] == Directions.None)
         {
             edges.Add(edge);
         }
     }
     if (origin.direction != Directions.Right)
     {
         var edge = new Edge(origin.x, origin.y, Directions.Left, origin.depth);
         if (Contains(edge.exit) && this[edge.exit] == Directions.None)
         {
             edges.Add(edge);
         }
     }
     if (origin.direction != Directions.Down)
     {
         var edge = new Edge(origin.x, origin.y, Directions.Up, origin.depth);
         if (Contains(edge.exit) && this[edge.exit] == Directions.None)
         {
             edges.Add(edge);
         }
     }
     if (origin.direction != Directions.Up)
     {
         var edge = new Edge(origin.x, origin.y, Directions.Down, origin.depth);
         if (Contains(edge.exit) && this[edge.exit] == Directions.None)
         {
             edges.Add(edge);
         }
     }
     return edges;
 }
Exemplo n.º 4
0
 public bool Contains(Cell cell)
 {
     return cell.x >= 0 && cell.x < width && cell.y >= 0 && cell.y < height;
 }
Exemplo n.º 5
0
 public Directions this[Cell cell]
 {
     get { return cells[cell.x, cell.y]; }
     set { cells[cell.x, cell.y] = value; }
 }
Exemplo n.º 6
0
        private IEnumerator GenerateCoroutine()
        {
            texture = new Texture2D(mazeWidth, mazeHeight, TextureFormat.ARGB32, false, true)
            {
                filterMode = FilterMode.Point
            };
            cellWidth = (mazeWidth - cellWallSize)/(cellSize + cellWallSize);
            cellHeight = (mazeHeight - cellWallSize)/(cellSize + cellWallSize);
            maze = new Maze(cellWidth, cellHeight);

            var origin = new Cell {x = Random.Range(0, cellWidth), y = Random.Range(0, cellHeight)};
            maze[origin] = Directions.None;
            edges = new List<Edge>(maze.GetEdges(origin));

            texture.Clear(Color.black);
            yield return null;

            switch (mazeAlgorithm)
            {
                case MazeAlgorithm.None:
                    if (RandomE.Chance(0.5f))
                    {
                        yield return StartCoroutine(RandomTraversal());
                    }
                    else
                    {
                        yield return StartCoroutine(RandomDepthFirstTraversal());
                    }
                    break;
                case MazeAlgorithm.RandomTraversal:
                    yield return StartCoroutine(RandomTraversal());
                    break;
                case MazeAlgorithm.RandomDepthFirstTraversal:
                    yield return StartCoroutine(RandomDepthFirstTraversal());
                    break;
            }

            texture.Apply();
        }