public void TestSetup()
 {
     this.unJuego = Juego.Instancia();
     this.unJuego.ComenzarDesdeElPrincipio();
     this.unJuego.SeleccionarMapa();
     this.unJuego.CargarMapa();
     this.unMapa = this.unJuego.Ambiente;
 }
Example #2
0
 public void CargarMapa()
 {
     RecomenzarNivel();
     this.guardador = new MapaArchivo();
     this.ambiente = guardador.ContinuarPartidaGuardada(archivoMapaActual);
     this.nivel = ambiente.NroNivel;
 }
        public void TestSetup()
        {
            //creo un mapa 5x5 con esta distribucion (P = Pasillo, * = BloqueAcero):
            //      P P P P P
            //      P * P * P
            //      P P P P P
            //      P * P * P
            //      P P P P P
            Juego.Reiniciar();
            Juego.Instancia().ComenzarDesdeElPrincipio();
            Punto unaPosicion;
            Casilla unaCasilla;
            this.unMapa = new Tablero(ANCHOMAPA, ANCHOMAPA);

            int i, j;
            for (i = 0; i < ANCHOMAPA; i++)
                for (j = 0; j < ANCHOMAPA; j++)
                {
                    unaPosicion = new Punto(i, j);
                    if ((i & 1) == 1 && (j & 1) == 1)
                    {
                        //ambos son numeros impares
                        unaCasilla = FabricaDeCasillas.FabricarCasillaConBloqueLadrillos(unaPosicion);
                    }
                    else
                    {
                        //uno de los dos es par
                        unaCasilla = FabricaDeCasillas.FabricarPasillo(unaPosicion);
                    }
                    this.unMapa.AgregarCasilla(unaCasilla);
                }
            Juego.Instancia().Ambiente = unMapa;
            Juego.Instancia().Protagonista = new Bombita(new Punto(0, 0));
        }
Example #4
0
 public void Inicializar(Tablero unMapa)
 {
     mapaInterno = unMapa;
     objetosDibujables = new List<ObjetoVivo>();
     enemigosDibujables = new List<ObjetoVivo>();
     pasillosDibujables = new List<ObjetoVivo>();
 }
Example #5
0
        public Tablero ContinuarPartidaGuardada(string pathName)
        {
            Casilla casillaActual = null;
            Punto posActual = null;
            Tablero tableroNuevo = new Tablero();
            try
            {

                StreamReader lector = new StreamReader(pathName);
                //Uso reflection a full
                String xmlString = lector.ReadToEnd();

                Type tipo;
                int res;
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreWhitespace = true;

                using (XmlReader reader = XmlReader.Create(new StringReader(xmlString), settings))
                {
                    //leo el inicio del mapa
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                            case XmlNodeType.Element:
                                //Es el tablero
                                if (reader.Name == "Tablero")
                                {
                                    tipo = Type.GetType("BombermanModel.Mapa." + reader.Name);
                                    tableroNuevo = Activator.CreateInstance(tipo) as Tablero;
                                    if (reader.HasAttributes) //deberia entrar, tiene 2 attr
                                    {
                                        tableroNuevo.DimensionHorizontal = Convert.ToInt32(reader.GetAttribute("ancho"));
                                        tableroNuevo.DimensionVertical = Convert.ToInt32(reader.GetAttribute("alto"));
                                        tableroNuevo.NroNivel = Convert.ToInt32(reader.GetAttribute("nivel"));
                                        tableroNuevo.StageName = reader.GetAttribute("mapa");
                                        if (reader.AttributeCount > 4)
                                        {
                                            elJuego.CantDeVidas = Convert.ToInt32(reader.GetAttribute("vidas"));
                                        }
                                    }
                                    elJuego.Ambiente = tableroNuevo;
                                }
                                else
                                {
                                    //es una casilla
                                    if (reader.Name == "Casilla")
                                    {
                                        int x, y;
                                        //leo coordenadas x e y
                                        x = Convert.ToInt32(reader.GetAttribute("x"));
                                        y = Convert.ToInt32(reader.GetAttribute("y"));
                                        if (reader.IsEmptyElement)
                                        {
                                            casillaActual = FabricaDeCasillas.FabricarPasillo(new Punto(x, y));
                                            tableroNuevo.AgregarCasilla(casillaActual);
                                        }
                                        else
                                        {
                                            posActual = new Punto(x, y);
                                        }
                                    }
                                    else
                                    {

                                        //es algun obstaculo
                                        if ((reader.Name.Length >= 6) && (reader.Name.Substring(0, 6).Equals("Bloque")))
                                        {
                                            res = Convert.ToInt32(reader.GetAttribute("resistencia"));
                                            switch (reader.Name)
                                            {
                                                case "BloqueLadrillo":
                                                    casillaActual = FabricaDeCasillas.FabricarCasillaConBloqueLadrillos(posActual);
                                                    break;
                                                case "BloqueCemento":
                                                    casillaActual = FabricaDeCasillas.FabricarCasillaConBloqueCemento(posActual);
                                                    break;
                                                case "BloqueAcero":
                                                    casillaActual = FabricaDeCasillas.FabricarCasillaConBloqueAcero(posActual);
                                                    break;
                                            }
                                            casillaActual.Estado.UnidadesDeResistencia = res;

                                            tableroNuevo.AgregarCasilla(casillaActual);

                                        }
                                        else //es un personaje o un articulo
                                        {
                                            if (!tableroNuevo.ExisteCasillaEnPosicion(posActual))
                                            {
                                                casillaActual = FabricaDeCasillas.FabricarPasillo(posActual);
                                                tableroNuevo.AgregarCasilla(casillaActual);
                                            }

                                            if (reader.HasAttributes) //es personaje
                                            {
                                                int vel = Convert.ToInt32(reader.GetAttribute("velocidad"));
                                                res = Convert.ToInt32(reader.GetAttribute("resistencia"));
                                                Personaje.Personaje p = null;
                                                if (reader.Name == "Bombita")
                                                {

                                                    p = new Bombita(posActual);
                                                    if (reader.AttributeCount > 2) //si el lanzador se guardo en el mapa
                                                    {
                                                        string lanz = reader.GetAttribute("lanzador");
                                                        tipo = Type.GetType("BombermanModel.Arma." + lanz);
                                                        Arma.Lanzador l = Activator.CreateInstance(tipo) as Arma.Lanzador;
                                                        p.Lanzador = l;
                                                    }
                                                    casillaActual.Transitar(p);
                                                    elJuego.Protagonista = p;
                                                    tableroNuevo.PosicionInicial = posActual;
                                                }
                                                else //es algun enemigo
                                                {
                                                    tipo = Type.GetType("BombermanModel.Personaje." + reader.Name);
                                                    p = Activator.CreateInstance(tipo, new object[] { posActual }) as Personaje.Personaje;
                                                    elJuego.AgregarEnemigo(p);
                                                }

                                                p.Movimiento.Velocidad = vel;
                                                p.UnidadesDeResistencia = res;
                                            }
                                            else //es articulo
                                            {
                                                tipo = Type.GetType("BombermanModel.Articulo." + reader.Name);
                                                Articulo.Articulo a = Activator.CreateInstance(tipo) as Articulo.Articulo;
                                                casillaActual.ArticuloContenido = a;
                                                if (reader.Name == "Salida")
                                                    elJuego.Salida = (Articulo.Salida)a;
                                            }
                                        }
                                    }
                                }
                                break;
                        }

                    }

                    return tableroNuevo;

                }
            }
            catch (FileNotFoundException)
            {
                throw new BombermanModel.Excepciones.NoExisteMapaArchivoException("No pudo abrirse el archivo " + pathName);
            }
            catch (Exception)
            {
                throw new BombermanModel.Excepciones.FormatoMapaXMLInvalidoException("Archivo de mapa " + pathName+" tiene formato invalido" );
            }
        }
Example #6
0
        public void TestSetup()
        {
            //creo un mapa 5x5 con esta distribucion (P = Pasillo, * = Obstaculo):
            //      P P P P P
            //      P * P * P
            //      P P P P P
            //      P * P * P
            //      P P P P P

            Punto unaPosicion;
            Casilla unaCasilla;
            this.unMapa = new Tablero(ANCHOMAPA, ANCHOMAPA);
            this.otroMapa = new Tablero(ANCHOMAPA, ANCHOMAPA);
            int i, j;
            for (i = 0; i < ANCHOMAPA; i++)
                for (j = 0; j < ANCHOMAPA; j++)
                {
                    unaPosicion = new Punto(i, j);
                    if ((i & 1) == 1 && (j & 1) == 1)
                    {
                        //ambos son numeros impares
                        unaCasilla = FabricaDeCasillas.FabricarCasillaConBloqueLadrillos(unaPosicion);//.FabricarCasillaConBloqueAcero(unaPosicion);
                    }
                    else
                    {
                        //uno de los dos es par
                        unaCasilla = FabricaDeCasillas.FabricarPasillo(unaPosicion);
                    }
                    this.unMapa.AgregarCasilla(unaCasilla);
                }
        }
        public void ExplotoUnObstaculoQueContieneUnaChalaYLuegoLoComeBombita()
        {
            int AnchoYLargo = 5;

            Tablero unMapa = new Tablero(AnchoYLargo, AnchoYLargo);
            Punto posInicio = new Punto(0, 0);
            Punto posFinal = new Punto(1, 1);
            Personaje unBombita = new Bombita(posInicio);

            //Pongo un BombaToleTole en el pasillo para agarrarlo con bombita y poder romper el bloque de acero donde esta la Chala
            Punto posicionCasillaArt = new Punto(0, 1);
            Casilla CasillaConArticulo = Juego.Instancia().Ambiente.ObtenerCasilla(posicionCasillaArt);
            Articulo unArticulo = new ArticuloBombaToleTole();
            CasillaConArticulo.ArticuloContenido = unArticulo;

            //Agrego articulo
            posicionCasillaArt = new Punto(1, 1);
            CasillaConArticulo = this.unJuego.Ambiente.ObtenerCasilla(posicionCasillaArt);
            unArticulo = new Chala();
            CasillaConArticulo.agregarArticulo(unArticulo);

            //Muevo a bombita para dejarlo cerca de un Bloque y explotarlo.
            this.unJuego.Ambiente.AgregarPersonaje(unBombita);
            float velocidad = unBombita.Movimiento.Velocidad;

            unBombita.Movimiento.CambiarAArriba();
            unBombita.Mover();//fue a 0,1
            unBombita.LanzarExplosivo();

            //Pongo a bombita lejos de la explosion
            unBombita.Movimiento.CambiarAAbajo();
            unBombita.Mover();//fue a 0,0
            unBombita.Movimiento.CambiarADerecha();
            unBombita.Mover(); //fue a 0,1

            System.Threading.Thread.Sleep(5000);//Pasan 5 segundos
            unJuego.AvanzarElTiempo();

            unBombita.Movimiento.CambiarAArriba();
            unBombita.Mover(); //fue a 1,1; come item.

            Assert.AreEqual(2 * velocidad, unBombita.Movimiento.Velocidad);
        }