Exemple #1
0
        public static void PrintConnections(List <BaseNodeConnection> connections, int vOffset, bool bold = false)
        {
            foreach (BaseNodeConnection con in connections)
            {
                Console.SetCursorPosition(con.NodeA.X, con.NodeA.Y + vOffset);
                if (con.NodeA.CharRepresentation != '\0')
                {
                    Console.Write(con.NodeA.CharRepresentation);
                }
                else
                {
                    Console.Write(TraceChars.paths[con.NodeA.PathIndex | (bold ? 16 : 0)]);
                }


                if (con.IsHorizontal)
                {
                    for (int i = Math.Min(con.NodeA.X, con.NodeB.X) + 1; i < Math.Max(con.NodeA.X, con.NodeB.X); i++)
                    {
                        Console.CursorLeft = i;
                        Console.Write(TraceChars.GetPathChar(false, false, true, true, bold));
                    }
                }
                else
                {
                    for (int i = Math.Min(con.NodeA.Y, con.NodeB.Y) + 1; i < Math.Max(con.NodeA.Y, con.NodeB.Y); i++)
                    {
                        Console.CursorLeft--;
                        Console.CursorTop = i + vOffset;
                        Console.Write(TraceChars.GetPathChar(true, true, false, false, bold));
                    }
                }

                Console.SetCursorPosition(con.NodeB.X, con.NodeB.Y + vOffset);
                if (con.NodeB.CharRepresentation != '\0')
                {
                    Console.Write(con.NodeB.CharRepresentation);
                }
                else
                {
                    Console.Write(TraceChars.paths[con.NodeB.PathIndex | (bold ? 16 : 0)]);
                }
            }
        }
Exemple #2
0
        private void GetNodes(string maze)
        {
            var mazeLines = maze.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            nodes       = new List <Node>();
            portals     = new List <Node>();
            connections = new List <BaseNodeConnection>();
            Node[] aboveNodes = new Node[mazeLines[0].Length];
            maxHeight = mazeLines.Length + 1;
            Point start = Point.Empty;
            Point end   = Point.Empty;


            for (int y = 0; y < mazeLines.Length; y++)
            {
                var currLine = mazeLines[y].Replace(' ', '#');
                if (start == Point.Empty)
                {
                    var startX = mazeLines[y].IndexOf('#');
                    if (startX >= 0)
                    {
                        start = new Point(startX, y);
                    }
                }
                else
                {
                    var endX = mazeLines[y].LastIndexOf('#');
                    if (endX >= 0)
                    {
                        end = new Point(endX, y);
                    }
                }
                mazeLines[y] = currLine;
                Node previousNode = null;
                for (int x = 0; x < currLine.Length; x++)
                {
                    var currPos = currLine[x];
                    if (currPos != wallChar)
                    {
                        var above = false;
                        var below = false;
                        var left  = false;
                        var right = false;
                        if (y > 0)
                        {
                            above = mazeLines[y - 1][x] != wallChar;
                        }
                        if (y < mazeLines.Length - 1)
                        {
                            below = mazeLines[y + 1][x] != wallChar;
                        }
                        if (x > 0)
                        {
                            left = mazeLines[y][x - 1] != wallChar;
                        }
                        if (x < currLine.Length - 1)
                        {
                            right = mazeLines[y][x + 1] != wallChar;
                        }

                        //!Av!BvLvR N   AvBv!Lv!R
                        if (((!above || !below || left || right) && (above || below || !left || !right)) || currPos != '.')
                        {
                            var currNode = new Node(x, y, currPos);
                            currNode.IsOuterPortal = x <start.X || y <start.Y || x> end.X || y> end.Y;
                            if (aboveNodes[x] != null)
                            {
                                connections.Add(new NodeConnection(currNode, aboveNodes[x]));
                            }
                            if (previousNode != null)
                            {
                                connections.Add(new NodeConnection(currNode, previousNode));
                            }
                            nodes.Add(currNode);

                            currNode.PathIndex = TraceChars.GetPathNumber(above, below, left, right, false);

                            aboveNodes[x] = currNode;
                            previousNode  = currNode;

                            Console.Write(currPos);
                        }
                        else
                        {
                            Console.Write(' ');
                        }
                    }
                    else
                    {
                        aboveNodes[x] = null;
                        previousNode  = null;
                        Console.Write(currPos);
                    }
                }
                Console.WriteLine();
            }
        }
Exemple #3
0
        private void GetNodes(string maze)
        {
            var mazeLines = maze.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            nodes       = new List <BaseNode>();
            keys        = new List <Node>();
            doors       = new List <Node>();
            connections = new List <BaseNodeConnection>();
            Node[] aboveNodes = new Node[mazeLines[0].Length];
            maxHeight = mazeLines.Length + 1;


            for (int y = 0; y < mazeLines.Length; y++)
            {
                var  currLine     = mazeLines[y];
                Node previousNode = null;
                for (int x = 0; x < currLine.Length; x++)
                {
                    var currPos = currLine[x];
                    if (currPos != wallChar)
                    {//Maze is Surrounded by Walls(#), thus no out of range check required.
                        var above = mazeLines[y - 1][x] != wallChar;
                        var below = mazeLines[y + 1][x] != wallChar;
                        var left  = mazeLines[y][x - 1] != wallChar;
                        var right = mazeLines[y][x + 1] != wallChar;

                        //!Av!BvLvR N   AvBv!Lv!R
                        if (((!above || !below || left || right) && (above || below || !left || !right)) || currPos != '.')
                        {
                            var currNode = new Node(x, y, currPos);
                            if (aboveNodes[x] != null)
                            {
                                connections.Add(new NodeConnection(currNode, aboveNodes[x]));
                            }
                            if (previousNode != null)
                            {
                                connections.Add(new NodeConnection(currNode, previousNode));
                            }
                            if (currNode.Key != '\0')
                            {
                                keys.Add(currNode);
                            }
                            if (currNode.Lock != '\0')
                            {
                                doors.Add(currNode);
                            }
                            nodes.Add(currNode);

                            currNode.PathIndex = TraceChars.GetPathNumber(above, below, left, right, false);

                            aboveNodes[x] = currNode;
                            previousNode  = currNode;
                            if (currPos == '@' && startNode == null)
                            {
                                startNode = currNode;
                            }

                            Console.Write(currPos);
                        }
                        else
                        {
                            Console.Write(' ');
                        }
                    }
                    else
                    {
                        aboveNodes[x] = null;
                        previousNode  = null;
                        Console.Write(currPos);
                    }
                }
                Console.WriteLine();
            }
        }