Exemplo n.º 1
0
 private void RemoveWall(MazeGeneratorCellNew current, MazeGeneratorCellNew chozen)
 {
     if (current.X == chozen.X)
     {
         if (current.Y > chozen.Y)
         {
             current.WallBottom = false;
         }
         else
         {
             chozen.WallBottom = false;
         }
     }
     else
     {
         if (current.X > chozen.X)
         {
             current.WallLeft = false;
         }
         else
         {
             chozen.WallLeft = false;
         }
     }
 }
Exemplo n.º 2
0
    private void PlaceMazeExit(MazeGeneratorCellNew[,] maze)
    {
        MazeGeneratorCellNew furthest = maze[0, 0];

        for (int x = 0; x < maze.GetLength(0); x++)
        {
            if (maze[x, Width - 2].DistanceFromStart > furthest.DistanceFromStart)
            {
                furthest = maze [x, Width - 2];
            }
            if (maze[x, 0].DistanceFromStart > furthest.DistanceFromStart)
            {
                furthest = maze [x, 0];
            }
        }

        for (int y = 0; y < maze.GetLength(1); y++)
        {
            if (maze[Width - 2, y].DistanceFromStart > furthest.DistanceFromStart)
            {
                furthest = maze [Width - 2, y];
            }
            if (maze[0, y].DistanceFromStart > furthest.DistanceFromStart)
            {
                furthest = maze [0, y];
            }
        }

        furthest.MazeExit = true;
    }
Exemplo n.º 3
0
    public MazeGeneratorCellNew[,] GenerateNewMaze(int width, int height, int sancturySideLen, bool ClosedSanctuary, int ClosedSanctuarySideLen)
    {
        Width              = width;
        Height             = height;
        SantuarySideLength = sancturySideLen;



        MazeGeneratorCellNew[,] maze = new MazeGeneratorCellNew [Width, Height];
        for (int w = 0; w < maze.GetLength(0); w++)
        {
            for (int l = 0; l < maze.GetLength(1); l++)
            {
                maze [w, l] = new MazeGeneratorCellNew(w, l);
            }
        }

        for (int x = 0; x < maze.GetLength(0); x++)
        {
            maze[x, Height - 1].WallLeft = false;
            maze[x, Height - 1].UnbreakableWallBottom = true;
            maze[x, 0].UnbreakableWallBottom          = true;
        }

        for (int y = 0; y < maze.GetLength(1); y++)
        {
            maze[Width - 1, y].WallBottom          = false;
            maze[Width - 1, y].UnbreakableWallLeft = true;
            maze[0, y].UnbreakableWallLeft         = true;
        }



        RemoveWallsWithBackTracker(maze);
        PlaceMazeExit(maze);
        PlaceMazeDoors(maze);
        PlaceMazeSanctuary(maze, ClosedSanctuary, ClosedSanctuarySideLen);

        return(maze);
    }
Exemplo n.º 4
0
    private void RemoveWallsWithBackTracker(MazeGeneratorCellNew[,] maze)
    {
        MazeGeneratorCellNew current = maze [0, 0];
        bool LastMoveWasTrue         = true;

        current.DistanceFromStart = 0;
        current.Visited           = true;

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

        //List<MazeGeneratorCellNew> CellsWithBlobs = new List<MazeGeneratorCellNew>();
        //List<string> Barriers = new List<string>();
        do
        {
            List <MazeGeneratorCellNew> unvisitedNeighbours = new List <MazeGeneratorCellNew>();

            int w = current.X;
            int l = current.Y;


            if (w > 0 && !maze[w - 1, l].Visited)
            {
                unvisitedNeighbours.Add(maze[w - 1, l]);
            }
            if (l > 0 && !maze[w, l - 1].Visited)
            {
                unvisitedNeighbours.Add(maze[w, l - 1]);
            }
            if (w < Width - 2 && !maze[w + 1, l].Visited)
            {
                unvisitedNeighbours.Add(maze[w + 1, l]);
            }
            if (l < Height - 2 && !maze[w, l + 1].Visited)
            {
                unvisitedNeighbours.Add(maze[w, l + 1]);
            }

            if (unvisitedNeighbours.Count > 0)
            {
                MazeGeneratorCellNew chozen = unvisitedNeighbours [UnityEngine.Random.Range(0, unvisitedNeighbours.Count)];

                RemoveWall(current, chozen);
                // if(CheckDoorsAndBlobs(CellsWithBlobs,Barriers).Count>0){
                //     int RandIndex = UnityEngine.Random.Range(0,CheckDoorsAndBlobs(CellsWithBlobs,Barriers).Count-1);
                //     Barriers.Add(CreatePortal(CheckDoorsAndBlobs(CellsWithBlobs,Barriers)[RandIndex], current,chozen));
                // }


                chozen.Visited = true;

                stack.Push(chozen);
                float Rand = UnityEngine.Random.Range(0f, 100f);
                if (Rand >= 90f)
                {
                    current.ShouldBeWithBlob = true;
                    // current.RandomBlob();
                    // CellsWithBlobs.Add(current);
                }
                LastMoveWasTrue          = true;
                current                  = chozen;
                chozen.DistanceFromStart = stack.Count;
            }
            else
            {
                if (LastMoveWasTrue)
                {
                    current.ShouldBeWithBlob = true;
                    //current.RandomBlob();
                    //CellsWithBlobs.Add(current);
                    LastMoveWasTrue = false;
                }

                current = stack.Pop();
            }
        }while (stack.Count > 0);
    }