示例#1
0
    public void ConnectRooms(ref GraphScript.Graph G, Room[] map, int mapSize)
    {
        Room  a, b, c;
        float abDist, acDist, bcDist;
        bool  skip;

        for (int i = 0; i < mapSize; ++i)
        {
            a = map[i];
            for (int j = i + 1; j < mapSize; ++j)
            {
                skip = false;
                b    = map[j];

                abDist = Mathf.Pow(a.CenterX() - b.CenterX(), 2) + Mathf.Pow(a.CenterY() - b.CenterY(), 2);
                for (int k = 0; k < mapSize; ++k)
                {
                    if (k == i || k == j)
                    {
                        continue;
                    }
                    c = map[k];

                    acDist = Mathf.Pow(a.CenterX() - c.CenterX(), 2) + Mathf.Pow(a.CenterY() - c.CenterY(), 2);
                    bcDist = Mathf.Pow(b.CenterX() - c.CenterX(), 2) + Mathf.Pow(b.CenterY() - c.CenterY(), 2);

                    if (acDist < abDist && bcDist < abDist)
                    {
                        skip = true;
                    }
                    if (skip)
                    {
                        break;
                    }
                }
                if (!skip)
                {
                    if (G.NodeList.Find(a) == null)
                    {
                        G.addNode(a, new LinkedList <Room>());
                    }
                    if (G.NodeList.Find(b) == null)
                    {
                        G.addNode(b, new LinkedList <Room>());
                    }
                    G.Dico[G.NodeList.Find(a).Value].AddLast(b);
                    G.Dico[G.NodeList.Find(b).Value].AddLast(a);
                }
            }
        }
    }
示例#2
0
    void Start()
    {
        Room[] map = GenerateRandomRoom(16, 16, 100, 256, 12);
        Debug.Log("GenerateRandom done");

        int offset = 0;

        GraphScript.Graph G = new GraphScript.Graph(0);
        ConnectRooms(ref G, map, 10);
        G.Depth(offset);

        foreach (Room r in map)
        {
            r.PrintRoom(w, g);
        }
        Debug.Log("Print done");
    }