コード例 #1
0
        public static bool Load(string xml_file)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(xml_file);

            // 加载资源
            XmlNodeList nodelist = xmlDoc.SelectNodes("//SectionRes/String");

            for (int i = 0; i < nodelist.Count; i++)
            {
                XmlElement e = (XmlElement)nodelist.Item(i);
                PuzzleRes.AddResource("Section", e.InnerText);
            }

            nodelist = xmlDoc.SelectNodes("//MusicRes/String");
            for (int i = 0; i < nodelist.Count; i++)
            {
                XmlElement e = (XmlElement)nodelist.Item(i);
                PuzzleRes.AddResource("Music", e.InnerText);
            }

            nodelist = xmlDoc.SelectNodes("//SceneRes/String");
            for (int i = 0; i < nodelist.Count; i++)
            {
                XmlElement e = (XmlElement)nodelist.Item(i);
                PuzzleRes.AddResource("Scene", e.InnerText);
            }

            nodelist = xmlDoc.SelectNodes("//ResolutionRes/Resolution");
            for (int i = 0; i < nodelist.Count; i++)
            {
                XmlElement e = (XmlElement)nodelist.Item(i);
                Resolution r = new Resolution();

                r.Width  = int.Parse(e.GetAttribute("width"));
                r.Height = int.Parse(e.GetAttribute("height"));
                r.Device = e.InnerText;
                PuzzleRes.AddResource("Resolution", r);
            }

            nodelist = xmlDoc.SelectNodes("//SizeRes/Int");
            for (int i = 0; i < nodelist.Count; i++)
            {
                XmlElement e = (XmlElement)nodelist.Item(i);
                PuzzleRes.AddResource("Size", int.Parse(e.InnerText));
            }

            nodelist = xmlDoc.SelectNodes("//BackgroundRes/String");
            for (int i = 0; i < nodelist.Count; i++)
            {
                XmlElement e = (XmlElement)nodelist.Item(i);
                PuzzleRes.AddResource("Background", e.InnerText);
            }

            // 加载场景资源
            nodelist = xmlDoc.SelectNodes("//GameRes/Section");
            for (int i = 0; i < nodelist.Count; ++i)
            {
                XmlElement e       = (XmlElement)nodelist.Item(i);
                Section    section = new Section();
                section.Name  = e.GetAttribute("name");
                section.Music = e.GetAttribute("music");

                XmlNodeList sceneNodeList = e.ChildNodes;

                for (int j = 0; j < sceneNodeList.Count; ++j)
                {
                    XmlElement ee = (XmlElement)sceneNodeList.Item(j);

                    Scene scene = new Scene();
                    scene.Name       = ee.GetAttribute("name");
                    scene.Background = ee.GetAttribute("background");

                    XmlNodeList resolNodeList = ee.ChildNodes;
                    for (int k = 0; k < resolNodeList.Count; ++k)
                    {
                        XmlElement eee = (XmlElement)resolNodeList.Item(k);

                        Resolution r     = new Resolution();
                        SceneResol resol = new SceneResol();

                        r.Width  = int.Parse(eee.GetAttribute("width"));
                        r.Height = int.Parse(eee.GetAttribute("height"));
                        r.Device = eee.GetAttribute("device");

                        resol.Resolution = r;
                        resol.Size       = int.Parse(eee.GetAttribute("size"));

                        XmlNodeList progmNodeList = eee.ChildNodes;
                        for (int m = 0; m < progmNodeList.Count; ++m)
                        {
                            XmlElement eeee = (XmlElement)progmNodeList.Item(m);

                            Programme programme = new Programme();

                            programme.ID = int.Parse(eeee.GetAttribute("id"));

                            XmlNodeList cubeNodeList = eeee.ChildNodes;
                            for (int n = 0; n < cubeNodeList.Count; ++n)
                            {
                                XmlElement eeeee = (XmlElement)cubeNodeList.Item(n);
                                Cube       cube  = new Cube();

                                cube.Type = int.Parse(eeeee.GetAttribute("type"));

                                string   content   = eeeee.InnerText;
                                char[]   separator = { '#' };
                                string[] st        = content.Split(separator);

                                foreach (string s in st)
                                {
                                    State state = new State();
                                    if (s.Contains("f"))
                                    {
                                        state.IsFliped = true;
                                    }
                                    else
                                    {
                                        state.IsFliped = false;
                                    }

                                    string tmp;
                                    if (state.IsFliped)
                                    {
                                        tmp = s.Substring(1, s.Length - 3);
                                    }
                                    else
                                    {
                                        tmp = s.Substring(1, s.Length - 2);
                                    }

                                    char[]   septr = { ',' };
                                    string[] temps = tmp.Split(septr);

                                    state.X = double.Parse(temps[0]);
                                    state.Y = double.Parse(temps[1]);
                                    state.R = double.Parse(temps[2]);

                                    cube.States.Add(state);
                                }

                                programme.Cubes[cube.Type - 1] = cube;
                            }
                            resol.Programmes.Add(programme);
                        }
                        scene.SceneResols.Add(resol);
                    }
                    section.Scenes.Add(scene);
                }
                GameRes.Sections.Add(section);
            }

            return(true);
        }
コード例 #2
0
        public override bool Equals(object obj)
        {
            Resolution o = obj as Resolution;

            return(o.Width == Width && o.Height == Height);
        }