Exemplo n.º 1
0
 private void AddPath(MazeNode node)
 {
     pathList.Add(node);
 }
Exemplo n.º 2
0
 public void AddNode(MazeNode node)
 {
     maze.AddGraphNode(node);
 }
Exemplo n.º 3
0
        private void InitalizeMaze(string path)
        {
            //Maze maze = new Maze();
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.DtdProcessing = DtdProcessing.Parse;
            XmlReader reader = XmlReader.Create($@"{path}", settings);

            //reading of the XML document
            while (reader.Read())
            {
                if (reader.NodeType != XmlNodeType.EndElement)
                {
                    //reading of the 'Maze' Node
                    switch (reader.Name)
                    {
                    //setting properties
                    case "xsize":
                    {
                        reader.Read();

                        Xsize = int.Parse(reader.Value);
                        break;
                    }

                    case "ysize":
                    {
                        reader.Read();
                        Ysize = int.Parse(reader.Value);
                        break;
                    }

                    //Reading of the individual MazeNode Nodes
                    case "MazeNode":
                    {
                        //creating a new node
                        MazeNode node = new MazeNode();
                        reader.Read();
                        //until we get to the end of the MazeNode Node
                        while (!(reader.NodeType == XmlNodeType.EndElement && reader.Name == "MazeNode"))
                        {
                            if (reader.NodeType != XmlNodeType.EndElement && reader.NodeType != XmlNodeType.Whitespace)
                            {
                                //read each Name and set properties accordingly
                                switch (reader.Name)
                                {
                                case "id":
                                {
                                    reader.Read();
                                    node.ID = int.Parse(reader.Value);
                                    break;
                                }

                                case "x":
                                {
                                    reader.Read();
                                    node.X = int.Parse(reader.Value);
                                    break;
                                }

                                case "y":
                                {
                                    reader.Read();
                                    node.Y = int.Parse(reader.Value);
                                    break;
                                }

                                case "NodeType":
                                {
                                    //Node types have 3 different types
                                    reader.Read();
                                    switch (reader.Value)
                                    {
                                    case "Start":
                                    {
                                        node.Type = NodeType.Start;
                                        break;
                                    }

                                    case "End":
                                    {
                                        node.Type = NodeType.End;
                                        break;
                                    }

                                    case "None":
                                    {
                                        node.Type = NodeType.None;
                                        break;
                                    }
                                    }
                                    break;
                                }

                                //cant add neighbors yet because some neighbors dont exsist yet
                                //instead store them in a list and add later
                                case "neighbors":
                                {
                                    reader.Read();
                                    string   strValue = reader.Value;
                                    string[] strList;

                                    strList = strValue.Split(',');

                                    foreach (string s in strList)
                                    {
                                        node.idsToEdge.Add(int.Parse(s));
                                    }
                                    break;
                                }
                                }
                            }
                            reader.Read();
                        }
                        //add the node to the graph
                        AddNode(node);
                        break;
                    }
                    }
                }
            }
            //now that we have added all the nodes in the graph we add the neighbors
            //AddNeighbors(maze);

            //return maze;
        }