Git Product home page Git Product logo

unity3d_maze_alpha-0.0.2's Introduction

Unity3d_Maze

  • Depth-First-Search

Mian code

1.Create Grid

 public void CerateGrid()
    {
        xLong = int.Parse(ip1.text);
        yLong = int.Parse(ip2.text);
        speed = float.Parse(sp1.text);

        wallHoder = new GameObject();
        wallHoder.name = "WallHolder";
        for(int i = 0; i <= xLong; i++)
            for(int j = 0; j < yLong; j++)
            {
                Vector3 pos = new Vector3(i - xLong / 2f, 0f, (yLong - 1f) / 2f - j);
                GameObject t = Instantiate(wallPrefab, pos, Quaternion.identity);
                t.transform.SetParent(wallHoder.transform);
            }

        for (int i = 0; i < xLong; i++)
            for (int j = 0; j <= yLong; j++)
            {
                Vector3 pos = new Vector3(i - (xLong - 1f) / 2f, 0f, yLong  / 2f - j);
                GameObject t = Instantiate(wallPrefab, pos, Quaternion.Euler(0f, 90f, 0f));
                t.transform.SetParent(wallHoder.transform);
            }
        CreateCell();
    }

2.CreateCell

    void CreateCell()
    {
        lastCells = new List<int>();
        lastCells.Clear();
        totalCell = xLong * yLong;
        int westEastNumber = 0;
        int northSouthNumber = 0;
        cells = new Cell[xLong * yLong];
        List<GameObject> allWalls = new List<GameObject>();

        for(int i = 0; i < wallHoder.transform.childCount; i++)
        {
            allWalls.Add(wallHoder.transform.GetChild(i).gameObject);
        }

        for(int i = 0; i < cells.Length; i++)
        {
            cells[i] = new Cell();
            cells[i].ID = i+1;
            cells[i].West = allWalls[westEastNumber];
            cells[i].East = allWalls[westEastNumber + yLong];

            cells[i].North = allWalls[northSouthNumber + xLong * yLong + yLong];
            cells[i].South = allWalls[northSouthNumber + xLong * yLong + yLong + 1];

            if((i+1)%yLong == 0)
            {
                northSouthNumber += 2;
            }
            else
            {
                northSouthNumber++;
            }
            cells[i].CellPos = new Vector3(cells[i].East.transform.position.x - .5f, 0f, cells[i].East.transform.position.z);

            westEastNumber++;
           

        }
        CreateMaze();
    }

Screen Shot

*---------------- 1 8 *---------------- 2 7

unity3d_maze_alpha-0.0.2's People

Contributors

personatsl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.