Example #1
0
        protected void recargarListPokegotchiPorIdUsuario(int idUsuario)
        {
            List <Pokegotchi> listaPokegotchi = new DALPokegotchi().RecuperaPokegotchisPorIdUsuario(Convert.ToInt32(Session["userId"]));

            if (!IsPostBack)
            {
                int           indice             = 0;
                Hashtable     listPokemonId      = new Hashtable();
                List <String> listaTextoPokemons = new List <string>();
                foreach (Pokegotchi pokegotchi in listaPokegotchi)
                {
                    listaTextoPokemons.Add(construirTextoPokemon(pokegotchi));
                    listPokemonId.Add(indice, pokegotchi.Id);
                    indice++;
                }
                Session["listPokemonId"] = listPokemonId;
                listPokemons.DataSource  = listaTextoPokemons;
                listPokemons.DataBind();
            }
            else
            {
                int       indice        = 0;
                Hashtable listPokemonId = new Hashtable();
                foreach (Pokegotchi pokegotchi in listaPokegotchi)
                {
                    data.Add(construirTextoPokemon(pokegotchi));
                    listPokemonId.Add(indice, pokegotchi.Id);
                    indice++;
                }
                Session["listPokemonId"] = listPokemonId;
                listPokemons.DataSource  = data;
                listPokemons.DataBind();
            }
        }
Example #2
0
        protected async void butCapturar_Click(object sender, EventArgs e)
        {
            if (textPedirPokemon.Text == "")
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Debe introducir un nombre de pokemon válido')", true);
            }
            else
            {
                try
                {
                    PokemonApi pokemonApi = await new DALPokemonApi().recuperarPokemonAPI(textPedirPokemon.Text);
                    if (pokemonApi != null)
                    {
                        DALPokegotchi dALPokegotchi = new DALPokegotchi();
                        if (!dALPokegotchi.ComprobarPokemonEnTabla(pokemonApi.Nombre))
                        {
                            dALPokegotchi.InsertarPokemon(pokemonApi);
                        }
                        Pokemon pokemonUsuario = dALPokegotchi.ObtenerIdPokemon(pokemonApi.Nombre);

                        dALPokegotchi.InsertarEnPokegotchi(pokemonUsuario, Convert.ToInt32(Session["userId"]));

                        recargarListPokegotchiPorIdUsuario(Convert.ToInt32(Session["userId"]));
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('El Pokémon introducido no existe, prueba con otro nombre')", true);
                    }
                }
                catch (Exception error) { }
            }
        }
Example #3
0
        protected void butJugar_Click(object sender, EventArgs e)
        {
            if (listPokemons.SelectedIndex == -1)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Selecciona un pokemon para poder jugar')", true);
            }
            else
            {
                Hashtable hashTableIdPokemons = new Hashtable();
                hashTableIdPokemons = (Hashtable)Session["listPokemonId"];
                DALPokegotchi dALpokegotchi = new DALPokegotchi();
                dALpokegotchi.AumentarFelicidad((int)hashTableIdPokemons[listPokemons.SelectedIndex]);
                dALpokegotchi.AumentarSalud((int)hashTableIdPokemons[listPokemons.SelectedIndex]);
                recargarListPokegotchiPorIdUsuario(Convert.ToInt32(Session["userId"]));

                //controlar si hemos ganado
                int felicidad = dALpokegotchi.SelectMediaFelicidadPokegotchiPorIdUsuario(Convert.ToInt32(Session["userId"]));
                int salud     = dALpokegotchi.SelectMediaSaludPokegotchiporIdUsuario(Convert.ToInt32(Session["userId"]));

                if (felicidad > 10 && salud > 10)
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('¡Feicidades! Acabas de conseguir tu Pokegotchi Legendario')", true);
                }
            }
        }
Example #4
0
 protected void listPokemons_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listPokemons.SelectedIndex != -1)
     {
         Hashtable ht = new Hashtable();
         ht = (Hashtable)Session["listPokemonId"];
         DALPokegotchi dALpokegotchi          = new DALPokegotchi();
         Pokegotchi    pokegotchiSeleccionado = dALpokegotchi.RecuperaPokegotchiPorId((int)ht[listPokemons.SelectedIndex]);
         Image1.ImageUrl = "https://pokeres.bastionbot.org/images/pokemon/" + pokegotchiSeleccionado.Pokemon.IdApi + ".png";
         Image1.DataBind();
     }
 }
Example #5
0
 protected void butRecolectar_Click(object sender, EventArgs e)
 {
     if (listPokemons.SelectedIndex == -1)
     {
         ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Selecciona un pokemon para poder recolectar')", true);
     }
     else
     {
         Hashtable hashTableIdPokemons = new Hashtable();
         hashTableIdPokemons = (Hashtable)Session["listPokemonId"];
         DALPokegotchi dALpokegotchi = new DALPokegotchi();
         dALpokegotchi.DisminuirFelicidad((int)hashTableIdPokemons[listPokemons.SelectedIndex]);
         dALpokegotchi.DisminuirSalud((int)hashTableIdPokemons[listPokemons.SelectedIndex]);
         recargarListPokegotchiPorIdUsuario(Convert.ToInt32(Session["userId"]));
     }
 }
        protected void butNuevaPartida_Click(object sender, EventArgs e)
        {
            DALPokegotchi daLPokegotchi = new DALPokegotchi();

            if (daLPokegotchi.SelectUsuario(textNombre.Text) == null && textNombre.Text != "")
            {
                daLPokegotchi.InsertarUsuario(textNombre.Text);
                Session["userId"]        = daLPokegotchi.ObtenerIdUsuario(textNombre.Text);
                Session["listPokemonId"] = new Hashtable();
                Response.Redirect("PaginaPokedex.aspx", false);
                Context.ApplicationInstance.CompleteRequest();
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Ya existe una partida con ese nombre. Prueba a introducir uno diferente')", true);
            }
        }
        protected void butCargarPartida_Click(object sender, EventArgs e)
        {
            DALPokegotchi daLPokegotchi = new DALPokegotchi();

            try
            {
                if (daLPokegotchi.SelectUsuario(textNombre.Text) != null)
                {
                    Session["userId"]        = daLPokegotchi.ObtenerIdUsuario(textNombre.Text);
                    Session["listPokemonId"] = new Hashtable();
                    Response.Redirect("PaginaPokedex.aspx", false);
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('No existe ninguna partida con ese nombre.')", true);
                }
            }
            catch (Exception error) { textNombre.Text = error.Message; }
        }