コード例 #1
0
    // Generate random maze using Kruskal's algorithm
    Maze GenerateMaze_Random()
    {
        if (!level.customMazeSize)
        {
            level.mazeWidth  = Formula.CalculateMazeSideSize(level.mazeDifficulty);
            level.mazeLength = Formula.CalculateMazeSideSize(level.mazeDifficulty);
        }

        Maze       maze    = new Maze(level.mazeWidth, level.mazeLength);
        GameObject mazeObj = new GameObject()
        {
            name = "Maze"
        };
        MazeBlueprint mazeBP = new MazeBlueprint(level.mazeWidth, level.mazeLength);

        for (int i = 0; i < level.mazeWidth; i++)
        {
            for (int j = 0; j < level.mazeLength; j++)
            {
                maze.mazeTile[i, j] = GenerateTileWithBlueprint(i, j, mazeBP);
                maze.mazeTile[i, j].transform.parent = mazeObj.transform;
                maze.mazeTileList.Add(maze.mazeTile[i, j]);
            }
        }

        return(maze);
    }
コード例 #2
0
    public void constructPartialMazeCenter(MazeBlueprint blueprint, int startRow, int startCol, int endRow, int endCol)
    {
        this.adjustBorder(ref blueprint, ref startRow, ref startCol, ref endRow, ref endCol);
        this.initTileList();
        this.initTilePositionList();

        int width  = (endCol - startCol);
        int height = (endRow - startRow);

        // center point
        int pivotX = startCol + width / 2;
        int pivotY = startRow + height / 2;

        for (int i = 0; i < height / 2; i++)
        {
            for (int j = 0; j < width / 2; j++)
            {
                if (!(this.isTileDrawn(pivotX + j, pivotY + i)))
                {
                    String tileType = blueprint.getTileType(pivotY + i, pivotX + j);
                    if (tileType != "Empty")
                    {
                        addTile(pivotX + j, pivotY + i, drawableTiles.getTile(tileType));
                    }
                }

                if (!(this.isTileDrawn(pivotX - j, pivotY + i)))
                {
                    String tileType = blueprint.getTileType(pivotY + i, pivotX - j);
                    if (tileType != "Empty")
                    {
                        addTile(pivotX - j, pivotY + i, drawableTiles.getTile(tileType));
                    }
                }
            }
            for (int j = 0; j < width / 2; j++)
            {
                if (!(this.isTileDrawn(pivotX + j, pivotY - i)))
                {
                    String tileType = blueprint.getTileType(pivotY - i, pivotX + j);
                    if (tileType != "Empty")
                    {
                        addTile(pivotX + j, pivotY - i, drawableTiles.getTile(tileType));
                    }
                }

                if (!(this.isTileDrawn(pivotX - j, pivotY - i)))
                {
                    String tileType = blueprint.getTileType(pivotY - i, pivotX - j);
                    if (tileType != "Empty")
                    {
                        addTile(pivotX - j, pivotY - i, drawableTiles.getTile(tileType));
                    }
                }
            }
        }
    }
コード例 #3
0
    // Generate script tile based on maze blueprint
    Tile GenerateTileWithBlueprint(int X, int Z, MazeBlueprint mazeBP)
    {
        bool[]     wall    = new bool[4];
        int        nbWalls = 0;
        WallLayout wallLayout;
        GameObject wallLayoutObj;
        int        rotCount = 0;

        // Get wall info from maze blueprint
        wall[0] = mazeBP.wall_h [X, Z + 1];            // N
        wall[1] = mazeBP.wall_v [X + 1, Z];            // E
        wall[2] = mazeBP.wall_h [X, Z];                // S
        wall[3] = mazeBP.wall_v [X, Z];                // W

        // Get number of walls
        for (int i = 0; i < wall.Length; i++)
        {
            if (wall[i])
            {
                nbWalls++;
            }
        }

        // Get wall layout, then setup object
        if ((wall [0] != wall [1]) && (wall [0] == wall [2]) && (wall [1] == wall [3]))
        {
            wallLayout = WallLayout.II;
        }
        else
        {
            wallLayout = (WallLayout)nbWalls;
        }

        wallLayoutObj = level.mazeSetting.GetWallLayoutObj(wallLayout);
        Utilities.TryCatchError((wallLayoutObj == null), "'TileLayout" + wallLayout + "' has wrong setup in current Maze Setting.");

        // Get rotation count for based on wall layout so we can rotate the wall layout later.
        rotCount = GetLayoutRotationCount(wall, wallLayout);

        // Spawn tile object
        GameObject tileObj = GameObject.Instantiate(wallLayoutObj, new Vector3(X * 10, -0, Z * 10), Quaternion.Euler(0, 90 * rotCount, 0));

        tileObj.name = "Tile [" + X + "]" + "[" + Z + "] " + "(" + wallLayout + ")";
        tileObj.AddComponent <Tile>();

        // Generate Tile class data
        Tile tile = tileObj.GetComponent <Tile>();

        tile.X          = X;
        tile.Z          = Z;
        tile.wall       = wall;
        tile.wallLayout = wallLayout;
        AssignWallFloorObjToTile(tile, wallLayout, rotCount);

        return(tile);
    }
コード例 #4
0
 private void SetupBlueprint()
 {
     try {
         throw new Exception("ehehehe");
         // this.mazeBlueprint = FetchBluePrint();
     } catch (Exception e) {
         this.mazeBlueprint = GenerateBlueprint();
         Debug.Log(e);
     }
 }
コード例 #5
0
 private MazeBlueprint FetchBluePrint()
 {
     try {
         var           serializedBlueprint = Util.Get(NetworkManager.BaseUrl + "/api/map?matchId=33");
         MazeBlueprint blueprint           = new MazeBlueprint(-1, -1);
         blueprint.deserialize(serializedBlueprint);
         return(blueprint);
     } catch (Exception e) {
         throw e;
     }
 }
コード例 #6
0
    public void GenerateBluePrint()
    {
        mazeBlueprint = new MazeBlueprint(this.maze.getHeight(), this.maze.getWidth());
        List <List <String> > playAreaBlueprint = new List <List <String> >();

        for (int i = 0; i < this.mazeHeight; i++)
        {
            List <String> newRow = new List <String>();
            for (int j = 0; j < this.mazeWidth; j++)
            {
                newRow.Add(this.maze.getTileType(i, j));
            }
            playAreaBlueprint.Add(newRow);
        }
        this.mazeBlueprint.setPlayAreaBlueprint(playAreaBlueprint);
    }
コード例 #7
0
    /* =================================================
    *                   Main Method
    *  ================================================= */

    public void constructMaze(MazeBlueprint blueprint)
    {
        this.initTileList();
        this.initTilePositionList();

        for (int i = 0; i < blueprint.getMazeHeight(); i++)
        {
            for (int j = 0; j < blueprint.getMazeWidth(); j++)
            {
                String tileType = blueprint.getTileType(i, j);
                if (tileType != "Empty")
                {
                    addTile(j, i, drawableTiles.getTile(tileType));
                }
            }
        }
    }
コード例 #8
0
 private void adjustBorder(ref MazeBlueprint blueprint, ref int startRow, ref int startCol, ref int endRow, ref int endCol)
 {
     if (startRow < 0)
     {
         startRow = 0;
     }
     if (endRow > blueprint.getMazeHeight())
     {
         endRow = blueprint.getMazeHeight();
     }
     if (startCol < 0)
     {
         startCol = 0;
     }
     if (endCol > blueprint.getMazeWidth())
     {
         endCol = blueprint.getMazeWidth();
     }
 }
コード例 #9
0
    public void constructPartialMaze(MazeBlueprint blueprint, int startRow, int startCol, int endRow, int endCol)
    {
        this.adjustBorder(ref blueprint, ref startRow, ref startCol, ref endRow, ref endCol);
        this.initTileList();
        this.initTilePositionList();

        for (int i = startRow; i < endRow; i++)
        {
            for (int j = startCol; j < endCol; j++)
            {
                if (this.isTileDrawn(j, i))
                {
                    break;
                }

                String tileType = blueprint.getTileType(i, j);
                if (tileType != "Empty")
                {
                    addTile(j, i, drawableTiles.getTile(tileType));
                }
            }
        }
    }
コード例 #10
0
 protected void Initialize()
 {
     mazeBlueprint = new MazeBlueprint(-1, -1);
     StartCoroutine(loadMazeBlueprint());
 }