Beispiel #1
0
 private static void RemoveWall(MazeGeneratorCell a, MazeGeneratorCell b)
 {
     if (a.X == b.X)
     {
         if (a.Y > b.Y)
         {
             a.WallBottom = false;
         }
         else
         {
             b.WallBottom = false;
         }
     }
     else
     {
         if (a.X > b.X)
         {
             a.WallLeft = false;
         }
         else
         {
             b.WallLeft = false;
         }
     }
 }
Beispiel #2
0
        public Maze GenerateMaze()
        {
            _width  = PlayerPrefs.GetInt("MapSize", 20);
            _height = _width;
            _plane  = PhotonNetwork.InstantiateRoomObject("Floor", new Vector3((_width * 10) - 5, 0, (_height * 10) - 5),
                                                          Quaternion.identity);
            _plane.transform.localScale = new Vector3(_width * 2, 1, _height * 2);
            var cells = new MazeGeneratorCell[_width, _height];

            for (var x = 0; x < cells.GetLength(0); x++)
            {
                for (var y = 0; y < cells.GetLength(1); y++)
                {
                    cells[x, y] = new MazeGeneratorCell {
                        X = x, Y = y
                    };
                }
            }

            for (var x = 0; x < cells.GetLength(0); x++)
            {
                cells[x, _height - 1].WallLeft = false;
                cells[x, 0].WallBottom         = false;
                cells[x, 0].WallCenter         = false;
            }

            for (var y = 0; y < cells.GetLength(1); y++)
            {
                cells[_width - 1, y].WallBottom = false;
                cells[0, y].WallLeft            = false;
                cells[0, y].WallCenter          = false;
            }

            cells[_width - 1, _height - 1].WallCenter = false;
            cells[_width - 1, _height - 2].WallLeft   = false;
            cells[_width - 2, _height - 1].WallBottom = false;
            cells[0, _height - 1].WallBottom          = false;
            cells[1, _height - 1].WallCenter          = false;
            cells[1, _height - 2].WallLeft            = false;
            cells[_width - 1, 0].WallLeft             = false;
            cells[_width - 2, 1].WallBottom           = false;
            cells[_width - 1, 1].WallCenter           = false;
            cells[0, 1].WallBottom = false;
            cells[1, 0].WallLeft   = false;
            cells[1, 1].WallCenter = false;

            RemoveWallsWithBacktracker(cells);

            var maze = new Maze {
                Cells = cells
            };

            return(maze);
        }