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(); } }
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(); } }