예제 #1
0
 public Partida(string n, DateTime t, Map m, Inventario i,Personaje j, Point p)
 {
     map=m;
     inv=i;
     jugador=j;
     pos=p;
 }
예제 #2
0
        //Escritor de doc XML para mapas
        public void WriteMap(string name,string path, Map m)
        {
            if(path=="")
                path="../../Mapas/";
            XmlWriterSettings conf = new XmlWriterSettings();
            conf.Indent = true;
            XmlWriter writer = XmlWriter.Create(path+name+".xml", conf);
            writer.WriteStartDocument();
            //writer.WriteComment("This file is generated by the program.");

            writer.WriteStartElement("Mapa");
            writer.WriteAttributeString("name", m.nombre);
            writer.WriteAttributeString("width", m.w.ToString());
            writer.WriteAttributeString("height", m.h.ToString());
            //Escribir recursos
            WriteSources(writer);
            //Escribir Elementos
            WriteElements(writer, m);
            //writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Flush();
            writer.Close();
        }
예제 #3
0
        public void WriteStaticElements(XmlWriter writer, Map m)
        {
            writer.WriteStartElement("Estaticos");
            List<Elemento> temp = new List<Elemento>();
            foreach (Elemento a in m.Ele)
            {
                if (a.type == "Estatico")
                    temp.Add(a);
            }
            while (temp.Count>0)
            {
                List<Elemento> iguales = new List<Elemento>();
                Elemento b = temp[0];
                foreach (Elemento a in temp)
                {
                    if (a.name == b.name)
                    {
                        iguales.Add(a);
                    }
                }
                writer.WriteComment(iguales[0].name);
                writer.WriteStartElement("Elemento");
                writer.WriteAttributeString("solido", b.solido.ToString());
                writer.WriteAttributeString("width", b._w.ToString());
                writer.WriteAttributeString("height", b._h.ToString());
                writer.WriteAttributeString("name", b.name.ToString());
                //writer.WriteAttributeString("type", b.type.ToString());
                //<imagen
                WriteImage(writer, b);
                //imagen>

                foreach (Elemento a in iguales)
                {
                    temp.Remove(a);
                    WritePosition(writer, a);
                }
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
        }
예제 #4
0
 public void WriteDinamicElements(XmlWriter writer, Map m)
 {
     writer.WriteStartElement("Dinamicos");
     WriteAnimatedElements(writer, m);
     WriteCaracter(writer, m);
     writer.WriteEndElement();
 }
예제 #5
0
 public void WriteElements(XmlWriter writer, Map m)
 {
     writer.WriteStartElement("Elementos");
     WriteStaticElements(writer, m);
     WriteDinamicElements(writer, m);
     writer.WriteEndElement();
 }
예제 #6
0
 //<-------------Termina esto
 public void CargarPersonaje(XmlNodeList _Dinamicos,ref Map _mapa)
 {
     XmlNodeList _Elemento = ((XmlElement)_Dinamicos[0]).GetElementsByTagName("Personaje");
     //------------------Cargar info del Elemento animado--------------------//
     foreach (XmlElement a in _Elemento)
     {       //---------------------------Cargando datos del elemento-----------------//
         string nombre = a.GetAttribute("name");
         string clase = a.GetAttribute("clase");
         float width = float.Parse(a.GetAttribute("width"));
         float height = float.Parse(a.GetAttribute("height"));
         string _accion = a.GetAttribute("accion");
         Personaje temp = new Personaje(0, 0, width, height,1, 0);
         //-----------------------Cargando datos de la imagen----------------//
         temp=(Personaje)CargarImagen(temp, a);
         //----------------------Cargando datos de animaciones----------------//
         List<Animacion> Acciones = CargarAnimacion(a,temp.im);
         //----------------------Cargar posiciones--------------------------//
         List<PointF> posiciones = CargarPosicion(a);
         foreach (PointF p in posiciones)
         {
             Personaje _E=null;
             switch (clase)
             {
                 case "Jugador":
                     _E = new Jugador(p.X, p.Y, width, height, _mapa.k, temp.profundidad);
                     _mapa.player = _mapa.Ele.Count;
                     _mapa.IM.mover = new MovimientoPersonaje(_E.Caminar);
                     _mapa.mover = new Moverse(_E.Moverse);
                     _E.clase = "Jugador";
                     break;
                 case "Enemigo":
                     _E = new Enemigo(p.X, p.Y, width, height, _mapa.k, temp.profundidad);
                     _E.clase = "Enemigo";
                     break;
                 case "NPC":
                     _E = new NPC(p.X, p.Y, width, height, _mapa.k, temp.profundidad);
                     _E.clase = "NPC";
                     break;
             }
             _E.AddImg(temp.im);
             _E.DefinePortion(temp.rec[1].X, temp.rec[1].Y, temp.rec[1].Width, temp.rec[1].Height);
             _E.acciones = Acciones;
             _E.SetAction(_accion, false);
             _E.name=nombre;
             CargarEstado(_E, a);
             _E.rec[2] = CargarCaja(a, _E);
             _E.type = "Personaje";
             _mapa.AddElemento(_E, p.X, p.Y);
         }
     }
 }
예제 #7
0
 public void WriteCaracter(XmlWriter writer, Map m)
 {
     List<Personaje> temp = new List<Personaje>();
     foreach (Elemento a in m.Ele)
     {
         if (a.type == "Personaje")
             temp.Add((Personaje)a);
     }
     while (temp.Count > 0)
     {
         List<Personaje> iguales = new List<Personaje>();
         Personaje b = temp[0];
         //iguales.Add(m.Ele[0]);
         foreach (Personaje a in temp)
         {
             if (a.name == b.name)
             {
                 iguales.Add(a);
             }
         }
         writer.WriteComment(iguales[0].name);
         writer.WriteStartElement("Personaje");
         writer.WriteAttributeString("clase", b.clase.ToString());
         writer.WriteAttributeString("width", b._w.ToString());
         writer.WriteAttributeString("height", b._h.ToString());
         writer.WriteAttributeString("accion", b.acciones[0].nombre);
         WriteImage(writer, b);
         WriteHitBox(writer, b);
         WriteStatus(writer, b);
         WriteAnimacion(writer, b);
         foreach (Personaje a in iguales)
         {
             temp.Remove(a);
             WritePosition(writer, a);
         }
         writer.WriteEndElement();
     }
 }
예제 #8
0
        public Map CargarMapa(string path, int w, int h,double k)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(path);
            XmlNodeList Ma = doc.GetElementsByTagName("Mapa");
            //---------------Elementos leidos y guardados--------------//
            string n=((XmlElement)Ma[0]).GetAttribute("name");
            //int offset = h / 16;
            int _w = int.Parse(((XmlElement)Ma[0]).GetAttribute("width"));
            int _h=int.Parse(((XmlElement)Ma[0]).GetAttribute("height"));

            //-------------------Creacion del Mapa--------------------//
            Map _mapa = new Map(n, 0, 0, _w, _h, (int)k);
            _mapa.SetFileManager(new FileHandler(GetImg));
            //------------------Cargar Imagenes y Audio--------------//
            CargarRecursos(Ma);
            CargarElementos(Ma, ref _mapa);
            return _mapa;
        }
예제 #9
0
 public void CargarElementos(XmlNodeList _map, ref Map _mapa)
 {
     XmlNodeList _Elementos = ((XmlElement)_map[0]).GetElementsByTagName("Elementos");
     CargarElementoEstatico(_Elementos, ref _mapa);
     CargarElementoDinamico(_Elementos,ref _mapa);
 }
예제 #10
0
 public void CargarElementoEstatico(XmlNodeList _Elementos, ref Map _mapa)
 {
     XmlNodeList _Estaticos = ((XmlElement)_Elementos[0]).GetElementsByTagName("Estaticos");
     XmlNodeList _Elemento = ((XmlElement)_Estaticos[0]).GetElementsByTagName("Elemento");
     foreach (XmlElement a in _Elemento)
     {
         //---------------------------Guardando datos del elemento-----------------//
         bool solid=bool.Parse(a.GetAttribute("solido"));
         float width=float.Parse(a.GetAttribute("width"));
         float height=float.Parse(a.GetAttribute("height"));
         string nombre = a.GetAttribute("name");
         Elemento temp=new Elemento(0,0,width,height,1,0,solid);
             //--------------------------Guardando Especificaciones de imagen------------//
         CargarImagen(temp, a);
             //---------------------------Guardando las posicion-----------------//
         List<PointF> posiciones=CargarPosicion(a);
             //---------------------------Agregar cada elemento al mapa----------//\
         foreach (PointF punto in posiciones)
         {
             Elemento _E =new Elemento(punto.X,punto.Y,temp.rec[0].Width,temp.rec[0].Height,_mapa.k,temp.profundidad,temp.solido);
             _E.AddImg(temp.im);
             _E.DefinePortion(temp.rec[1].X, temp.rec[1].Y, temp.rec[1].Width, temp.rec[1].Height);
             _E.name = nombre;
             _E.type = "Estatico";
             _mapa.AddElemento(_E, punto.X, punto.Y);
         }
             //_mapa.AddElemento(temp.im,temp.profundidad,temp.rec[0].Width,temp.Height,punto.Y,punto.Y,temp,temp.rec[0])
     }
 }
예제 #11
0
 public void CargarElementoDinamico(XmlNodeList _Elementos,ref Map _mapa)
 {
     XmlNodeList _Dinamicos = ((XmlElement)_Elementos[0]).GetElementsByTagName("Dinamicos");
     CargarElementoAnimado(_Dinamicos,ref _mapa);
     CargarPersonaje(_Dinamicos,ref _mapa);
 }
예제 #12
0
 public void CargarElementoAnimado(XmlNodeList _Dinamicos,ref Map _mapa)
 {
     XmlNodeList _Elemento = ((XmlElement)_Dinamicos[0]).GetElementsByTagName("Elemento_Animado");
     //------------------Cargar info del Elemento animado--------------------//
     foreach (XmlElement a in _Elemento)
     {       //---------------------------Cargando datos del elemento-----------------//
         bool solid = bool.Parse(a.GetAttribute("solido"));
         float width = float.Parse(a.GetAttribute("width"));
         float height = float.Parse(a.GetAttribute("height"));
         Elemento_Ani temp = new Elemento_Ani(0, 0, width, height, 1, 0, solid);
         //-----------------------Cargando datos de la imagen----------------//
         temp=(Elemento_Ani)CargarImagen(temp, a);
         //----------------------Cargando datos de animaciones----------------//
         temp.ani = CargarAnimacion(a,temp.im)[0];
         //----------------------Cargar posiciones--------------------------//
         List<PointF> posiciones=CargarPosicion(a);
         foreach (PointF punto in posiciones)
         {
             Elemento_Ani _E = new Elemento_Ani(punto.X, punto.Y, temp.rec[0].Width, temp.rec[0].Height, _mapa.k, temp.profundidad, temp.solido);
             _E.AddImg(temp.im);
             _E.DefinePortion(temp.rec[1].X, temp.rec[1].Y, temp.rec[1].Width, temp.rec[1].Height);
             _E.AddAnimation(temp.ani,new FileHandler(GetImg));
             _E.type = "Animado";
             _mapa.AddElemento(_E, punto.X, punto.Y);
         }
     }
 }