当前位置: 首页>>代码示例>>C#>>正文


C# Maze.CreateMaze方法代码示例

本文整理汇总了C#中Maze.CreateMaze方法的典型用法代码示例。如果您正苦于以下问题:C# Maze.CreateMaze方法的具体用法?C# Maze.CreateMaze怎么用?C# Maze.CreateMaze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Maze的用法示例。


在下文中一共展示了Maze.CreateMaze方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateMazeMap

    private void GenerateMazeMap()
    {
        GameObject wallsObject = GameObject.Find("Environment/Walls");
        var maze = new Maze(rows, columns);
        maze.CreateMaze();
        maze.OutputMap("Maze.txt");
        ////Maze.SaveMap("Maze.xml");

        if (cornerGraph)
        {
            List<Vector3> cornerWaypoints = getWaypointPositions((Maze)maze);

            World.Instance.Waypoints = cornerWaypoints;
        }

        var horizontalWallScale = new Vector3(cellWidth, WALL_HEIGHT, WALL_THICKNESS);
        var verticalWallScale = new Vector3(WALL_THICKNESS, WALL_HEIGHT, cellHeight);

        GameObject horizontalWall;
        GameObject verticalWall;

        Vector3 thicknessAdjustment;
        Vector3 lengthAdjustment;

        for (int j = 0; j < columns; j++)
        {
            var horizontalWallPosition =
                new Vector3(
                    World.Instance.Center.x - World.Instance.Size.x / 2 + j * cellWidth + cellWidth / 2.0f,
                    transform.position.y + transform.localScale.y / 2.0f,
                    World.Instance.Center.y - World.Instance.Size.y / 2);

            horizontalWall = Instantiate(wallTemplate, horizontalWallPosition, Quaternion.identity) as GameObject;
            horizontalWall.transform.localScale = horizontalWallScale;
            horizontalWall.name = "Horizontal_Wall_-1_" + j;

            thicknessAdjustment = new Vector3(0, 0, -WALL_THICKNESS / 2);
            horizontalWall.transform.localScale += thicknessAdjustment;
            horizontalWall.transform.Translate(-thicknessAdjustment / 2);

            horizontalWall.transform.parent = wallsObject.transform;
        }

        for (int i = 0; i < rows; i++)
        {
            var verticalWallPosition =
                new Vector3(
                    World.Instance.Center.x - World.Instance.Size.x / 2,
                    transform.position.y + transform.localScale.y / 2.0f,
                    World.Instance.Center.y - World.Instance.Size.y / 2 + i * cellHeight + cellHeight / 2.0f);

            verticalWall = Instantiate(wallTemplate, verticalWallPosition, Quaternion.identity) as GameObject;
            verticalWall.transform.localScale = verticalWallScale;
            verticalWall.name = "Vertical_Wall_" + i + "_-1";

            thicknessAdjustment = new Vector3(-WALL_THICKNESS / 2, 0, 0);
            verticalWall.transform.localScale += thicknessAdjustment;
            verticalWall.transform.Translate(-thicknessAdjustment / 2);

            if (i == 0 || maze.Labrynth[i - 1, 0].Bottom)
            {
                lengthAdjustment = new Vector3(0, 0, -WALL_THICKNESS / 2);
                verticalWall.transform.localScale += lengthAdjustment;
                verticalWall.transform.Translate(-lengthAdjustment / 2);
            }

            if (maze.Labrynth[i, 0].Bottom)
            {
                lengthAdjustment = new Vector3(0, 0, -WALL_THICKNESS / 2);
                verticalWall.transform.localScale += lengthAdjustment;
                verticalWall.transform.Translate(lengthAdjustment / 2);
            }

            verticalWall.transform.parent = wallsObject.transform;

            for (int j = 0; j < columns; j++)
            {
                if (maze.Labrynth[i, j].Bottom)
                {
                    var horizontalWallPosition =
                        new Vector3(
                            World.Instance.Center.x - World.Instance.Size.x / 2 + j * cellWidth + cellWidth / 2.0f,
                            transform.position.y + transform.localScale.y / 2.0f,
                            World.Instance.Center.y - World.Instance.Size.y / 2 + i * cellHeight + cellHeight);

                    horizontalWall = Instantiate(wallTemplate, horizontalWallPosition, Quaternion.identity) as GameObject;
                    horizontalWall.transform.localScale = horizontalWallScale;
                    horizontalWall.name = "Horizontal_Wall_" + i + "_" + j;

                    if (j != 0 && !maze.Labrynth[i, j - 1].Bottom)
                    {
                        lengthAdjustment = new Vector3(WALL_THICKNESS / 2, 0, 0);
                        horizontalWall.transform.localScale += lengthAdjustment;
                        horizontalWall.transform.Translate(-lengthAdjustment / 2);
                    }

                    if (j != columns - 1 && !maze.Labrynth[i, j + 1].Bottom)
                    {
                        lengthAdjustment = new Vector3(WALL_THICKNESS / 2, 0, 0);
                        horizontalWall.transform.localScale += lengthAdjustment;
//.........这里部分代码省略.........
开发者ID:B-Rich,项目名称:377asn4,代码行数:101,代码来源:MapGenerator.cs


注:本文中的Maze.CreateMaze方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。