示例#1
0
        void getLevel(int level)
        {
            if(level >= levels.Count)
                level = 0;
            if(level < 0)
                level = levels.Count - 1;

            XDocument lvlDoc = XDocument.Load(levels[level].FullName);
            CurrentLevel = GameLevel.Load(Game, lvlDoc);
            pos = level;
        }
示例#2
0
        public static GameLevel Load(Game Game, XDocument Level)
        {
            try {
                GameLevel l = new GameLevel(Game);
                Assembly asm = Assembly.GetExecutingAssembly();

                XElement info = Level.Root.Element("Level").Element("Info");
                var obstacles = from o in Level.Root.Element("Level").Elements("Obstacle")
                                let type = asm.GetTypes().Where(t => t.FullName.ToLower().EndsWith("." + o.Element("Type").Value.ToLower())).FirstOrDefault()
                                where type != null
                                select new {
                                    Block = (MovableBlock)asm.CreateInstance(
                                        type.FullName, true, BindingFlags.CreateInstance, null, new object[] { Game.Content }, null, null
                                    ),
                                    Location = new Point(int.Parse(o.Element("X").Value), int.Parse(o.Element("Y").Value))
                                };

                l.Name = info.Element("Name").Value;
                l.Author = info.Element("Author").Value;
                l.Description = info.Element("Description").Value;

                foreach(var o in obstacles)
                    l.board.AddObstacle(o.Block, o.Location);

                return l;
            } catch {
                // Well we got an invalid level file or something.  Fail silently
                return null;
            }
        }