Example #1
0
        public static Jogo AbrirJogo(string arquivo, GameProxy gameProxy, ContentManager content, GraphicsDeviceManager graphics)
        {
            Jogo jogo = new Jogo(arquivo);

            jogo.LerArquivoJogo(gameProxy, content, graphics);
            return(jogo);
        }
Example #2
0
 public Game1()
 {
     graphics = new GraphicsDeviceManager(this);
     Content.RootDirectory = "Content";
     _GameProxy = new GameProxy(this);
     IsMouseVisible = true;
 }
Example #3
0
 public static Jogo AbrirJogo(string arquivo, GameProxy gameProxy, ContentManager content, GraphicsDeviceManager graphics)
 {
     Jogo jogo = new Jogo(arquivo);
     jogo.LerArquivoJogo(gameProxy, content, graphics);
     return jogo;
 }
Example #4
0
        private void LerArquivoJogo(GameProxy gameProxy, ContentManager content, GraphicsDeviceManager graphics)
        {
            XmlDocument document = new XmlDocument();
            document.Load(Arquivo);
            XmlNode nodeJogo = document.GetElementsByTagName("Jogo")[0];
            PropertyInfo p;
            Type type = typeof(ConcentradorObjeto);
            ConcentradorObjeto o;
            Type typeOriginal;
            Type baseInterface;
            XmlAttribute attribute;
            Cena cena;

            foreach (XmlNode cenaNode in nodeJogo.ChildNodes)
            {
                if (cenaNode.Name == "Cena")
                {
                    cena = new Cena();
                    cena.Nome = cenaNode.Attributes["Nome"].Value;
                    cena.Cor = System.Drawing.Color.FromArgb(int.Parse(cenaNode.Attributes["Cor"].Value));
                    ListaCena.Add(cena);

                    foreach (XmlNode objetoNode in cenaNode.SelectNodes("Objetos/Objeto"))
                    {
                        typeOriginal = Assembly.GetAssembly(type).GetType(objetoNode.Attributes["type"].Value);
                        o = (ConcentradorObjeto)typeOriginal.GetConstructor(new Type[] { typeof(Jogo) }).Invoke(new object[] { this });
                        baseInterface = o.BaseInterface;
                        foreach (XmlNode nodeProp in objetoNode.ChildNodes[0].ChildNodes)
                        {
                            attribute = nodeProp.Attributes[0];
                            if (attribute.Name == "Nome")
                            {
                                o.Nome = attribute.Value;
                            }
                            else
                            {
                                p = baseInterface.GetProperty(attribute.Name);
                                if (p.PropertyType == typeof(int))
                                {
                                    p.SetValue(o.XNAControl, Convert.ToInt32(attribute.Value), null);
                                }
                                else if (p.PropertyType == typeof(float))
                                {
                                    p.SetValue(o.XNAControl, float.Parse(attribute.Value), null);
                                }
                                else if (p.PropertyType == typeof(System.Drawing.Color))
                                {
                                    System.Drawing.Color c = System.Drawing.Color.FromArgb(int.Parse(attribute.Value));
                                    p.SetValue(o.XNAControl, c, null);
                                }
                                else
                                {
                                    p.SetValue(o.XNAControl, attribute.Value, null);
                                }
                            }
                        }
                        if (objetoNode.ChildNodes.Count > 1)
                        {
                            XmlNode nodeScript = objetoNode.ChildNodes[1];
                            string assemblyFile = nodeScript.Attributes["Assembly"].Value;
                            Assembly assembly = Assembly.LoadFrom(assemblyFile);
                            Type userType = assembly.GetTypes()[0];
                            IObjetoScript script = (IObjetoScript)userType.GetConstructor(new Type[]{
                         typeof(GameProxy), typeof(ICogEngineXNAControl)
                        }).Invoke(new object[] { gameProxy, o.XNAControl });
                            o.Script = script;
                        }
                        o.XNAControl.LoadContent(content, graphics.GraphicsDevice);
                        cena.AdicionarObjeto(o);
                    }
                }
            }

            SomXNA som;
            foreach (XmlNode nodeSom in nodeJogo.SelectNodes("Sons/Som"))
            {
                som = new SomXNA(this);
                attribute = nodeSom.Attributes["CaminhoArquivo"];
                som.CaminhoRelativo = attribute.Value;
                attribute = nodeSom.Attributes["Nome"];
                som.Nome = attribute.Value;
                som.Iniciar();
                ListaSom.Add(som);
            }
        }
Example #5
0
        private void LerArquivoJogo(GameProxy gameProxy, ContentManager content, GraphicsDeviceManager graphics)
        {
            XmlDocument document = new XmlDocument();

            document.Load(Arquivo);
            XmlNode            nodeJogo = document.GetElementsByTagName("Jogo")[0];
            PropertyInfo       p;
            Type               type = typeof(ConcentradorObjeto);
            ConcentradorObjeto o;
            Type               typeOriginal;
            Type               baseInterface;
            XmlAttribute       attribute;
            Cena               cena;

            foreach (XmlNode cenaNode in nodeJogo.ChildNodes)
            {
                if (cenaNode.Name == "Cena")
                {
                    cena      = new Cena();
                    cena.Nome = cenaNode.Attributes["Nome"].Value;
                    cena.Cor  = System.Drawing.Color.FromArgb(int.Parse(cenaNode.Attributes["Cor"].Value));
                    ListaCena.Add(cena);

                    foreach (XmlNode objetoNode in cenaNode.SelectNodes("Objetos/Objeto"))
                    {
                        typeOriginal  = Assembly.GetAssembly(type).GetType(objetoNode.Attributes["type"].Value);
                        o             = (ConcentradorObjeto)typeOriginal.GetConstructor(new Type[] { typeof(Jogo) }).Invoke(new object[] { this });
                        baseInterface = o.BaseInterface;
                        foreach (XmlNode nodeProp in objetoNode.ChildNodes[0].ChildNodes)
                        {
                            attribute = nodeProp.Attributes[0];
                            if (attribute.Name == "Nome")
                            {
                                o.Nome = attribute.Value;
                            }
                            else
                            {
                                p = baseInterface.GetProperty(attribute.Name);
                                if (p.PropertyType == typeof(int))
                                {
                                    p.SetValue(o.XNAControl, Convert.ToInt32(attribute.Value), null);
                                }
                                else if (p.PropertyType == typeof(float))
                                {
                                    p.SetValue(o.XNAControl, float.Parse(attribute.Value), null);
                                }
                                else if (p.PropertyType == typeof(System.Drawing.Color))
                                {
                                    System.Drawing.Color c = System.Drawing.Color.FromArgb(int.Parse(attribute.Value));
                                    p.SetValue(o.XNAControl, c, null);
                                }
                                else
                                {
                                    p.SetValue(o.XNAControl, attribute.Value, null);
                                }
                            }
                        }
                        if (objetoNode.ChildNodes.Count > 1)
                        {
                            XmlNode       nodeScript   = objetoNode.ChildNodes[1];
                            string        assemblyFile = nodeScript.Attributes["Assembly"].Value;
                            Assembly      assembly     = Assembly.LoadFrom(assemblyFile);
                            Type          userType     = assembly.GetTypes()[0];
                            IObjetoScript script       = (IObjetoScript)userType.GetConstructor(new Type[] {
                                typeof(GameProxy), typeof(ICogEngineXNAControl)
                            }).Invoke(new object[] { gameProxy, o.XNAControl });
                            o.Script = script;
                        }
                        o.XNAControl.LoadContent(content, graphics.GraphicsDevice);
                        cena.AdicionarObjeto(o);
                    }
                }
            }

            SomXNA som;

            foreach (XmlNode nodeSom in nodeJogo.SelectNodes("Sons/Som"))
            {
                som                 = new SomXNA(this);
                attribute           = nodeSom.Attributes["CaminhoArquivo"];
                som.CaminhoRelativo = attribute.Value;
                attribute           = nodeSom.Attributes["Nome"];
                som.Nome            = attribute.Value;
                som.Iniciar();
                ListaSom.Add(som);
            }
        }