public void Tocar(string nome) { SomXNA som = (SomXNA)_Jogo.ListarSom().FirstOrDefault(s => s.Nome == nome); if (som != null) { som.Tocar(); } }
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); } }