Exemple #1
0
    private void createDungeonPath()
    {
        // begin algorithm get first node of graph
        current = (RoomNodes)notInPath [Random.Range(0, notInPath.Count)];
        notInPath.Remove(current);
        inPath.Add(current);

        // keep connecting nodes -- ends when reaches node with no unconnected neighbors that are not already in the path
        RoomNodes previous = current;

        previousNodeID = previous.getID();
        while ((current = current.getRandomUnconnectedNeighbor(previousNodeID)) != null)
        {
            previousNodeID = previous.getID();

            if (previous.connectTwoNeighbors(current))
            {
                current.connectTwoNeighbors(previous);

                notInPath.Remove(current);
                inPath.Add(current);

                previous = current;
            }
            else
            {
                break;
            }
        }


        // some nodes may still be unconnected, the next stage is to connect them to a neighbor whom is attached until all remaining nodes are connected.
        connectUnconnectedNodes(2);
    }