示例#1
0
        // Recursively build the firing pattern dependency chains
        public AbstractFiringPattern NestedFiringPatterns(AbstractFiringPattern firingPattern, XElement xlevel)
        {
            if (xlevel == null)
            {
                return(null);
            }

            foreach (XElement xel in xlevel.Elements("firingpattern"))
            {
                //var newFiringPattern = NestedFiringPatterns(firingPattern,);
                string name = xel.Attribute("type").Value;
                AbstractFiringPattern newFiringPattern = FiringFactory.Build(name);
                double start = Double.Parse(xel.Attribute("start").Value);
                double stop  = Double.Parse(xel.Attribute("stop").Value);
                newFiringPattern.SetTimeWindow(start, stop);
                if (xel.Element("options") != null)
                {
                    var options = xel.Element("options");
                    newFiringPattern.WithOptions(options);
                    newFiringPattern.WithCoreOptions(options);
                }
                firingPattern.And(newFiringPattern);

                // continue on the dependency chain
                NestedFiringPatterns(newFiringPattern, xel);
            }

            return(firingPattern);
        }
示例#2
0
        public void ParseGameContentXML(XDocument x)
        {
            foreach (XElement xel in x.Root.Elements())
            {
                BaseModel model;
                if (xel.Attribute("type").Value == "Generic")
                {
                    model = modelFactory.BuildGenericEnemyModel(
                        xel.Attribute("type").Value,
                        xel.Attribute("texture").Value,
                        Double.Parse(xel.Attribute("startlife").Value),
                        Double.Parse(xel.Attribute("endlife").Value),
                        new Point(Int32.Parse(xel.Attribute("x").Value), Int32.Parse(xel.Attribute("y").Value)),
                        Int32.Parse(xel.Attribute("health").Value),
                        Double.Parse(xel.Attribute("speed").Value));
                }
                else
                {
                    model = modelFactory.Build(
                        xel.Attribute("type").Value,
                        xel.Attribute("texture") != null ? xel.Element("texture").Value : xel.Attribute("type").Value,
                        Double.Parse(xel.Attribute("startlife").Value),
                        Double.Parse(xel.Attribute("endlife").Value),
                        Int32.Parse(xel.Attribute("x").Value),
                        Int32.Parse(xel.Attribute("y").Value));
                    model.SetRate(xel.Attribute("speed") != null ? Double.Parse(xel.Attribute("speed").Value) : model.Rate);
                }

                foreach (XElement xxel in xel.Elements())
                {
                    if (xxel.Name.LocalName == "move")
                    {
                        string name = xxel.Attribute("type").Value;
                        AbstractMovePattern movePattern = MoveFactory.Build(name);

                        // we have options
                        if (xxel.Element("options") != null)
                        {
                            var options = xxel.Element("options");
                            movePattern.WithOptions(options);
                        }
                        double start = Double.Parse(xxel.Attribute("start").Value);
                        double stop  = Double.Parse(xxel.Attribute("stop").Value);
                        MoveController.From(model).Between(start, stop).Pattern(movePattern);
                    }
                    else if (xxel.Name.LocalName == "firingpattern")
                    {
                        // set the required parameters for the initial firing pattern
                        string name = xxel.Attribute("type").Value;
                        AbstractFiringPattern firingPattern = FiringFactory.Build(name);
                        double start = Double.Parse(xxel.Attribute("start").Value);
                        double stop  = Double.Parse(xxel.Attribute("stop").Value);

                        // parse any extra options
                        if (xxel.Element("options") != null)
                        {
                            var options = xxel.Element("options");
                            firingPattern.WithOptions(options);
                            firingPattern.WithCoreOptions(options);
                        }

                        // get the base firing pattern
                        firingPattern = FiringController.From(model).Between(start, stop).Pattern(firingPattern);

                        // handle firing patterns for all bullets based off the base firing pattern
                        NestedFiringPatterns(firingPattern, xxel);
                    }
                }
            }
        }