Ejemplo n.º 1
0
        public static Level CreateLevel(int height, int width)
        {
            string[,] textRepr = new string[height, width];
            //This has a size of 0 * 100 and placement in the middle to have a starting point for children.
            DungeonData parentData = new DungeonData {
                TopX = 0, TopY = 100, Width = 0, Height = 0
            };
            DungeonData leftData = new DungeonData {
                TopX = 0, TopY = 0, Width = 250, Height = 100
            };
            DungeonData rightData = new DungeonData {
                TopX = 0, TopY = 100, Width = 250, Height = 100
            };
            NodeDungeon parentNode = new NodeDungeon(parentData);
            TreeDungeon tree       = new TreeDungeon(parentNode);

            tree.InsertNewNode(leftData.TopY, leftData);
            tree.InsertNewNode(rightData.TopY, rightData);
            InsertNewNodeDungeons(tree);

            List <NodeDungeon> dNodes = new List <NodeDungeon>();

            dNodes   = tree.GetDungeonNodes(tree.rootNode, dNodes);
            dNodes   = CreateDungeonRooms(dNodes);
            textRepr = ConvertDungeonToText(dNodes, height, width);

            Level newLevel = new Level(textRepr);

            return(newLevel);
        }
Ejemplo n.º 2
0
        public override void InOrder(NodeDungeon rootNodeDungeon, int purpose)
        {
            if (rootNodeDungeon != null)
            {
                InOrder(rootNodeDungeon.LeftChild, purpose);
                switch (purpose)
                {
                case 0:     // Create room.
                    ;
                    break;

                case 1:     // Get room from NodeDungeon, for printing.
                    ;
                    break;

                case 2:     // If room has no children, create new children
                    CreateNewNodeDungeonsFromLeaf(rootNodeDungeon);
                    break;

                case 3:     // Debugging, writes the toString to console.
                    System.Console.WriteLine(rootNodeDungeon.ToString());
                    break;

                default:     // Create room, again, i guess, as a temporary thing.
                    ;
                    break;
                }
                // This (the switch case) is placed here, in the middle, with the purpose of only
                // poking around with the data once, after we've exhausted the
                // left part of the tree. Or, i might be wrong. Anywhyhow...
                InOrder(rootNodeDungeon.RightChild, purpose);
            }
        }
Ejemplo n.º 3
0
 public List <NodeDungeon> GetDungeonNodes(NodeDungeon node, List <NodeDungeon> nodeDungeons)
 {
     if (node != null)
     {
         nodeDungeons = GetDungeonNodes(node.LeftChild, nodeDungeons);
         if (node.LeftChild == null && node.RightChild == null)
         {
             nodeDungeons.Add(node);
         }
         nodeDungeons = GetDungeonNodes(node.RightChild, nodeDungeons);
     }
     return(nodeDungeons);
 }
Ejemplo n.º 4
0
        public virtual void InOrder(NodeDungeon rootNodeDungeon, int purpose)
        {
            if (rootNodeDungeon != null)
            {
                InOrder(rootNodeDungeon.LeftChild, purpose);
                switch (purpose)
                {
                case 0:
                    System.Console.WriteLine(rootNodeDungeon.ToString());
                    break;

                default:     // Create room, again, i guess, as a temporary thing.
                    ;
                    break;
                }
                InOrder(rootNodeDungeon.RightChild, purpose);
            }
        }
Ejemplo n.º 5
0
        public NodeDungeon FindNode(int nKey)
        {
            NodeDungeon currentNode = rootNode;

            while (currentNode.NKey != nKey)
            {
                if (nKey < currentNode.NKey)
                {
                    currentNode = currentNode.LeftChild;
                }
                else
                {
                    currentNode = currentNode.RightChild;
                }
                if (currentNode == null)
                {
                    return(null);
                }
            }
            return(currentNode);
        }
Ejemplo n.º 6
0
        public void InsertNewNode(int nKey, DungeonData dungeonData)
        {
            NodeDungeon newNode = new NodeDungeon(dungeonData);

            if (rootNode == null)
            {
                rootNode = newNode;
            }
            else
            {
                NodeDungeon currentDungeon = rootNode;
                NodeDungeon parentDungeon;
                while (true)
                {
                    parentDungeon = currentDungeon;

                    if (nKey < currentDungeon.NKey)
                    {
                        currentDungeon = currentDungeon.LeftChild;
                        if (currentDungeon == null)
                        {
                            parentDungeon.LeftChild = newNode;
                            return;
                        }
                    }
                    else
                    {
                        currentDungeon = currentDungeon.RightChild;
                        if (currentDungeon == null)
                        {
                            parentDungeon.RightChild = newNode;
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public void CreateNewNodeDungeonsFromLeaf(NodeDungeon nodeDungeon)
 {
     if (nodeDungeon.LeftChild == null && nodeDungeon.RightChild == null)
     {
         int MAXHEIGHT = nodeDungeon.DungeonData.Height;
         int MAXWIDTH  = nodeDungeon.DungeonData.Width;
         if (MAXHEIGHT < 4 || MAXWIDTH < 5)   // Too small to make new Dungeon, so ignore.
         {
             return;
         }
         DungeonData leftChildData  = null;
         DungeonData rightChildData = null;
         NodeDungeon leftChild      = null;
         NodeDungeon rightChild     = null;
         DungeonData nodeData       = nodeDungeon.DungeonData;
         int         splitDirection = Main.randomize.Next(0, 2);
         if (splitDirection == 0)   // Split vertically: ||
         {
             int split;
             if (MAXWIDTH == 6)
             {
                 split = 3;
             }
             else
             {
                 split = Main.randomize.Next(1, MAXWIDTH);
             }
             leftChildData = new DungeonData {
                 TopX = nodeData.TopX, TopY = nodeData.TopY, Width = split, Height = nodeData.Height
             };
             rightChildData = new DungeonData {
                 TopX   = nodeData.TopX + split,
                 TopY   = nodeData.TopY,
                 Width  = nodeData.Width - split,
                 Height = nodeData.Height
             };
             leftChild  = new NodeDungeon(leftChildData);
             rightChild = new NodeDungeon(rightChildData);
         }
         else if (splitDirection == 1)     // Split horizontally: ---
         {
             int split;
             if (MAXHEIGHT == 6)
             {
                 split = 3;
             }
             else
             {
                 split = Main.randomize.Next(1, MAXHEIGHT);
             }
             leftChildData = new DungeonData {
                 TopX = nodeData.TopX, TopY = nodeData.TopY, Width = nodeData.Width, Height = split
             };
             rightChildData = new DungeonData {
                 TopX   = nodeData.TopX,
                 TopY   = nodeData.TopY + split,
                 Width  = nodeData.Width,
                 Height = nodeData.Height - split
             };
             leftChild  = new NodeDungeon(leftChildData);
             rightChild = new NodeDungeon(rightChildData);
         }
         nodeDungeon.LeftChild   = leftChild;
         nodeDungeon.RightChild  = rightChild;
         nodeDungeon.DungeonData = null;
     }
 }
Ejemplo n.º 8
0
 public TreeDungeon(NodeDungeon rootNode) : base(rootNode)
 {
 }
Ejemplo n.º 9
0
 public Tree(NodeDungeon rootNode)
 {
     this.rootNode = rootNode;
 }