Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a new instance of the <see cref="SetGraphic" /> class
        /// with properties loaded in from XML
        /// </summary>
        /// <param name="xml">XML to read the properties from</param>
        public SetGraphic(XmlNode xml)
            : base(GraphicType.Set, xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException(nameof(xml));
            }

            // Create graphics
            Graphics = new List <BaseGraphic>();
            foreach (XmlNode graphicXML in xml.ChildNodes)
            {
                // Create the graphic
                BaseGraphic graphic = null;

                switch (graphicXML.Attributes["type"].Value)
                {
                case "animated":
                    graphic = new AnimatedGraphic(graphicXML);
                    break;

                case "static":
                    graphic = new StaticGraphic(graphicXML);
                    break;

                case "scrolling":
                    graphic = new ScrollingGraphic(graphicXML);
                    break;
                }

                // Add the graphic
                Graphics.Add(graphic);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a new instance of the <see cref="Level" /> class
        /// with properties populated from XML
        /// </summary>
        /// <param name="file">Full file path</param>
        /// <param name="xml">XML to read</param>
        public Level(string file, XmlDocument xml)
            : this()
        {
            if (xml == null)
            {
                throw new ArgumentNullException(nameof(xml));
            }

            // Load the file name
            FileName = file;

            // Read the info section
            Name = xml.ChildNodes[0].ChildNodes[0].Attributes["name"].Value;

            // Read each graphic as a graphic element
            foreach (XmlNode graphicXML in xml.ChildNodes[0].ChildNodes[1].ChildNodes)
            {
                // Create the graphic
                BaseGraphic graphic = null;

                switch (graphicXML.Attributes["type"].Value)
                {
                case "animated":
                    graphic = new AnimatedGraphic(graphicXML);
                    break;

                case "static":
                    graphic = new StaticGraphic(graphicXML);
                    break;

                case "scrolling":
                    graphic = new ScrollingGraphic(graphicXML);
                    break;

                case "set":
                    graphic = new SetGraphic(graphicXML);
                    break;
                }

                // Add the graphic
                Graphics.Add(graphic);
            }

            // Read entity as an entity element
            foreach (XmlNode entityXML in xml.ChildNodes[0].ChildNodes[2].ChildNodes)
            {
                // Read backgrounds directly and move on
                if (entityXML.Attributes["type"].Value == "background" ||
                    entityXML.Attributes["type"].Value == "player" ||
                    entityXML.Attributes["type"].Value == "turret")
                {
                    Ignorables.Add(entityXML.OuterXml);
                    continue;
                }

                // Must have a graphic
                string graphicID = entityXML.Attributes["graphic"].Value;
                if (String.IsNullOrWhiteSpace(graphicID))
                {
                    continue;
                }

                // Must have a graphic that exists
                BaseGraphic graphic = Graphics.FirstOrDefault(g => g.ID == graphicID);
                if (graphic == null)
                {
                    continue;
                }

                // Create the entity
                Entity entity = new Entity(entityXML, graphic.GetSize());

                // Add the entity
                Entities.Add(entity);
            }

            // Order the entities in the desired order
            Entities = Entities.OrderBy(e => e.Delay.HasValue ? e.Delay.Value : 0)
                       .ThenBy(e => e.Type).ToList();
        }