Beispiel #1
0
        public Map(string XmlPath)
        {
            var doc = new XmlDocument();
            doc.Load(XmlPath);

            //Basic
            var root = doc.SelectSingleNode("Map");

            LevelIndex = root.Attributes["LevelIndex"].InnerText;
            MapIndex = root.Attributes["MapIndex"].InnerText;
            Title = root.Attributes["Title"].InnerText;
            Description = root.Attributes["Description"].InnerText;
            Creator = root.Attributes["Creator"].InnerText;

            //Points
            var nodes = root.SelectSingleNode("Node");
            Node = new List<Point>();
            foreach (XmlNode x in nodes.ChildNodes)
            {
                //Basic
                var p = new Point();
                p.Type = x.Attributes["Type"] != null ? (PointType)Enum.Parse(typeof(PointType), x.Attributes["Type"].InnerText) : PointType.Normal;
                p.X = x.Attributes["X"] != null ? int.Parse(x.Attributes["X"].InnerText) : 0;
                p.Y = x.Attributes["Y"] != null ? int.Parse(x.Attributes["Y"].InnerText) : 0;
                p.CanSkip = x.Attributes["CanSkip"] != null ? Convert.ToBoolean(int.Parse(x.Attributes["CanSkip"].InnerText)) : false;
                p.Name = x.Attributes["Name"] != null ? x.Attributes["Name"].InnerText : "Start";

                //Routes
                var rx = x.SelectSingleNode("Routes");
                p.Routes = new List<Route>();
                if (rx != null)
                    foreach (XmlNode routex in rx.ChildNodes)
                    {
                        var s = new Route();
                        s.Target = routex.Attributes["Target"].InnerText;
                        s.Star = routex.Attributes["Star"] != null ? int.Parse(routex.Attributes["Star"].InnerText) : 0;
                        p.Routes.Add(s);
                    }

                //Enemies
                var ex = x.SelectSingleNode("Enemies");
                p.Enemies = new List<Fleet>();
                if (ex != null)
                    foreach (XmlNode enemx in ex.ChildNodes)
                    {
                        var e = new Fleet();
                        e.ID = int.Parse(enemx.Attributes["ID"].InnerText);
                        p.Enemies.Add(e);
                    }

                //Items
                var ix = x.SelectSingleNode("Items");
                p.Items = new List<Item>();
                if (ix != null)
                    foreach (XmlNode itemx in ix.ChildNodes)
                    {
                        var i = new Item();
                        i.Type = (ItemType)Enum.Parse(typeof(ItemType), itemx.Attributes["Type"].InnerText);
                        i.Value = int.Parse(itemx.Attributes["Value"].InnerText);
                        p.Items.Add(i);
                    }
                if (ex == null && ix != null)
                    p.Type = PointType.Resources;
                if (ex == null && ix == null)
                    p.Type = PointType.Anchor;
                if (p.CanSkip)
                    p.Type = PointType.CanSkip;

                Node.Add(p);
            }

            //Fleets
            Fleets = new List<Fleet>();
            var fn = root.SelectSingleNode("Fleets");
            foreach (XmlNode x in fn.ChildNodes)
            {
                var f = new Fleet();
                f.ID = int.Parse(x.Attributes["ID"].InnerText);
                f.Ships = new List<BaseShip>();
                foreach (XmlNode sx in x)
                {
                    var s = new BaseShip();
                    s.ID = int.Parse(sx.Attributes["ID"].InnerText);
                    f.Ships.Add(s);
                }
                Fleets.Add(f);
            }
            CheckWays(Node[0]);
        }
Beispiel #2
0
        public Map(string XmlPath)
        {
            var doc = new XmlDocument();

            doc.Load(XmlPath);

            //Basic
            var root = doc.SelectSingleNode("Map");

            LevelIndex  = root.Attributes["LevelIndex"].InnerText;
            MapIndex    = root.Attributes["MapIndex"].InnerText;
            Title       = root.Attributes["Title"].InnerText;
            Description = root.Attributes["Description"].InnerText;
            Creator     = root.Attributes["Creator"].InnerText;

            //Points
            var nodes = root.SelectSingleNode("Node");

            Node = new List <Point>();
            foreach (XmlNode x in nodes.ChildNodes)
            {
                //Basic
                var p = new Point();
                p.Type = x.Attributes["Type"] != null ? (PointType)Enum.Parse(typeof(PointType), x.Attributes["Type"].InnerText) : PointType.Normal;
                p.X    = x.Attributes["X"] != null?int.Parse(x.Attributes["X"].InnerText) : 0;

                p.Y = x.Attributes["Y"] != null?int.Parse(x.Attributes["Y"].InnerText) : 0;

                p.CanSkip = x.Attributes["CanSkip"] != null?Convert.ToBoolean(int.Parse(x.Attributes["CanSkip"].InnerText)) : false;

                p.Name = x.Attributes["Name"] != null ? x.Attributes["Name"].InnerText : "Start";

                //Routes
                var rx = x.SelectSingleNode("Routes");
                p.Routes = new List <Route>();
                if (rx != null)
                {
                    foreach (XmlNode routex in rx.ChildNodes)
                    {
                        var s = new Route();
                        s.Target = routex.Attributes["Target"].InnerText;
                        s.Star   = routex.Attributes["Star"] != null?int.Parse(routex.Attributes["Star"].InnerText) : 0;

                        p.Routes.Add(s);
                    }
                }

                //Enemies
                var ex = x.SelectSingleNode("Enemies");
                p.Enemies = new List <Fleet>();
                if (ex != null)
                {
                    foreach (XmlNode enemx in ex.ChildNodes)
                    {
                        var e = new Fleet();
                        e.ID = int.Parse(enemx.Attributes["ID"].InnerText);
                        p.Enemies.Add(e);
                    }
                }

                //Items
                var ix = x.SelectSingleNode("Items");
                p.Items = new List <Item>();
                if (ix != null)
                {
                    foreach (XmlNode itemx in ix.ChildNodes)
                    {
                        var i = new Item();
                        i.Type  = (ItemType)Enum.Parse(typeof(ItemType), itemx.Attributes["Type"].InnerText);
                        i.Value = int.Parse(itemx.Attributes["Value"].InnerText);
                        p.Items.Add(i);
                    }
                }
                if (ex == null && ix != null)
                {
                    p.Type = PointType.Resources;
                }
                if (ex == null && ix == null)
                {
                    p.Type = PointType.Anchor;
                }
                if (p.CanSkip)
                {
                    p.Type = PointType.CanSkip;
                }

                Node.Add(p);
            }

            //Fleets
            Fleets = new List <Fleet>();
            var fn = root.SelectSingleNode("Fleets");

            foreach (XmlNode x in fn.ChildNodes)
            {
                var f = new Fleet();
                f.ID    = int.Parse(x.Attributes["ID"].InnerText);
                f.Ships = new List <BaseShip>();
                foreach (XmlNode sx in x)
                {
                    var s = new BaseShip();
                    s.ID = int.Parse(sx.Attributes["ID"].InnerText);
                    f.Ships.Add(s);
                }
                Fleets.Add(f);
            }
            CheckWays(Node[0]);
        }