Exemplo n.º 1
0
        public static Map LoadMapFromXml(string mapname)
        {
            string path = filePath + mapname.ToLower() + ".xml";

            XmlDocument doc = new XmlDocument();
            doc.Load(path);

            XmlNode root = doc.DocumentElement;

            // get attributes of map - width and heigth
            int x = int.Parse(root.Attributes["width"].Value);
            int y = int.Parse(root.Attributes["heigth"].Value);
            int playerX = int.Parse(root.Attributes["playerX"].Value);
            int playerY = int.Parse(root.Attributes["playerY"].Value);

            Map newmap = new Map();
            newmap.CreateMapField(x,y);
            newmap.PlayerX = playerX;
            newmap.PlayerY = playerY;

            foreach (XmlNode node in root.ChildNodes)
            {
                Location l = LoadLocationFromXml((XmlElement)node);
                newmap.AddLocation(l);
                l.UpdateSymbol();
            }

            return newmap;
        }