Android - Problema con los gif en una aplicacion

 
Vista:
sin imagen de perfil

Problema con los gif en una aplicacion

Publicado por Kugo (4 intervenciones) el 12/01/2017 12:27:06
Buenas, un compañero y yo de clase de fp superior programación queremos crear un juego en Android Studio, el juego trata de un emparejados con personajes infantiles (Dragon ball, sinchan, doraemon, etc), queremos emparejar por ejemplo Sinchan y sinchan que salga un gif animado de sinchan y en cambio si pulsas sinchan y masao(otro personaje) se produzca un fallo pero aparte aparezca otro gif (SInchan pegando a Masao). El problema surge cuando fallas con otro personaje no se produce una transición del gif (Queremos que cada pareja tenga un Gif exclusivo) solo aparecen la de sinchan y la del error de doraemon. ¿Como podemos hacer para que se alternen los Gif depende de la pareja? A Continuación os paso código:
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Problema con los gif en una aplicacion

Publicado por Kugo (4 intervenciones) el 12/01/2017 13:46:56
Aqui os dejo el codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package com.example.alumno.memo;
 
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
 
import java.util.Random;
 
/**
 * Created by alumno on 14/12/16.
 */
 
public class Play extends AppCompatActivity {
    ImageView carta[][] = new ImageView[4][4];
    ImageView par[] = new ImageView[2];
    int levantamientos = 0;
    int aciertos = 0;
    public static int MILISEGUNDOS_ESPERA = 200;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play);
 
        ImageView img00 = (ImageView) findViewById(R.id.btn1);
        ImageView img01 = (ImageView) findViewById(R.id.btn2);
        ImageView img02 = (ImageView) findViewById(R.id.btn3);
        ImageView img03 = (ImageView) findViewById(R.id.btn4);
        ImageView img10 = (ImageView) findViewById(R.id.btn5);
        ImageView img11 = (ImageView) findViewById(R.id.btn6);
        ImageView img12 = (ImageView) findViewById(R.id.btn7);
        ImageView img13 = (ImageView) findViewById(R.id.btn8);
        ImageView img20 = (ImageView) findViewById(R.id.btn9);
        ImageView img21 = (ImageView) findViewById(R.id.btn10);
        ImageView img22 = (ImageView) findViewById(R.id.btn11);
        ImageView img23 = (ImageView) findViewById(R.id.btn12);
        ImageView img30 = (ImageView) findViewById(R.id.btn13);
        ImageView img31 = (ImageView) findViewById(R.id.btn14);
        ImageView img32 = (ImageView) findViewById(R.id.btn15);
        ImageView img33 = (ImageView) findViewById(R.id.btn16);
        ImageView img34 = (ImageView) findViewById(R.id.btn17);
 
        /*CAPTURAMOS LAS IMAGENES DE TODOS LOS IMAGEVIEW EN ORDEN*/
        Drawable imagenes[] = {img00.getDrawable(), img01.getDrawable(),
                img02.getDrawable(), img03.getDrawable(),
                img10.getDrawable(), img11.getDrawable(),
                img12.getDrawable(), img13.getDrawable(),
                img20.getDrawable(), img21.getDrawable(),
                img22.getDrawable(), img23.getDrawable(),
                img30.getDrawable(), img31.getDrawable(),
                img32.getDrawable(), img33.getDrawable()};
 
        /*ASIGNAMOS A CADA CELDA DEL ARRAY UNA IMAGEVIEW*/
        carta[0][0] = img00;
        carta[0][1] = img01;
        carta[0][2] = img02;
        carta[0][3] = img03;
        carta[1][0] = img10;
        carta[1][1] = img11;
        carta[1][2] = img12;
        carta[1][3] = img13;
        carta[2][0] = img20;
        carta[2][1] = img21;
        carta[2][2] = img22;
        carta[2][3] = img23;
        carta[3][0] = img30;
        carta[3][1] = img31;
        carta[3][2] = img32;
        carta[3][3] = img33;
 
        Button reiniciar = (Button) findViewById(R.id.btnreiniciar);
        reiniciar.setEnabled(false);
 
        /*ASIGNAMOS A CADA IMAGEVIEW UN VALOR DEL ARRAY DRAWABLE*/
        Random aleatorio = new Random();
        int i = 0;
        int id = 0;
        while (i < 16) {
            int fila = aleatorio.nextInt(4);
            int columna = aleatorio.nextInt(4);
            if (carta[fila][columna].getTag().equals("no")) {
                carta[fila][columna].setTag(id);
                carta[fila][columna].setImageDrawable(imagenes[i]);
                i++;
                if (i != 0 && (i % 2 == 0)) {
					/*ESTE VALOR SERA EL QUE COMPROBAREMOS MAS ADELANTE PARA SABER SI LAS IMAGENES COINCIDEN*/
                    id++;
                }
            }
        }
    }
 
    /*METODO PARA OCULTAR TODAS LAS IMAGENES*/
    public void ocultar(View boton) {
        Button reiniciar = (Button) findViewById(R.id.btnreiniciar);
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                carta[i][j].setVisibility(View.INVISIBLE);
            }
        }
        boton.setEnabled(false);
    }
 
    /*METODO QUE REALIZA LA VISUALIZACION DE LAS IMAGENES LEVANTADAS*/
    public void levantar(View boton) {
        int fila = Integer.parseInt((boton.getTag().toString()).substring(0, 1));
        int columna = Integer.parseInt((boton.getTag().toString()).substring(1));
 
 
 
    /*COMPROBAREMOS SI LA TARJETA YA HA SIDO ELEGIDA, DE SER ASI SALIMOS DEL METODO*/
        if ((carta[fila][columna].getVisibility()) != View.VISIBLE) {
            carta[fila][columna].setVisibility(View.VISIBLE);
 
			/*GUARDAMOS LA DIRECCION DEL LAYOUT QUE SE HA LEVANTADO*/
            par[levantamientos] = carta[fila][columna];
            levantamientos++;
 
			/*SOLO SE COMPROBARA SI HEMOS LEVANTADO DOS VECES*/
            if (levantamientos == 2) {
 
				/*LLAMAMOS AL METODO ESPERAR*/
                esperar(MILISEGUNDOS_ESPERA);
            }
        } else {
            Toast.makeText(this, "Tarjeta ya elegida", Toast.LENGTH_SHORT).show();
        }
    }
 
    /*COMPROBACION DE SI LAS DOS IMAGENES LEVANTADAS SON IGUALES*/
    public void comprobar(){
        if(par[0].getTag()==par[1].getTag()){
            Toast.makeText(this,"Has acertado!!!!", Toast.LENGTH_SHORT).show();
            aciertos++;
        }
        else{
            Toast.makeText(this,"Has fallado!!!", Toast.LENGTH_SHORT).show();
            par[0].setVisibility(View.INVISIBLE);
            par[1].setVisibility(View.INVISIBLE);
        }
 
		/*REINICIAMOS LOS LEVANTAMIENTOS*/
        levantamientos=0;
 
		/*SI SE HAN ADIVINADO LAS TRES PAREJAS HABILITAMOS EL BOTON REINICIAR*/
        if(aciertos==8){
            Button reiniciar=(Button)findViewById(R.id.btnreiniciar);
            reiniciar.setEnabled(true);
        }
    }
 
    /*METODO ESPERAR*/
	/*LO UTILIZAMOS PARA PODER VER LAS IMAGENES EN CASO DE QUE NO SEAN IGUALES*/
    public void esperar(int milisegundos) {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
	            	/*ACCIÓN QUE SE EJECUTA PASADOS LOS MILISEGUNDOS*/
                comprobar();
            }
        }, milisegundos);
    }
 
    /*METODO REINICIAR PARTIDA*/
    public static void reiniciarActivity(Activity actividad){
        Intent intent=new Intent();
        intent.setClass(actividad, actividad.getClass());
        /*LLAMADA A LA ACTIVIDAD*/
        actividad.startActivity(intent);
        /*FINALIZAMOS LA ACTIVIDAD ACTUAL*/
        actividad.finish();
    }
 
    public void iniciar(View boton){
        aciertos=0;
        reiniciarActivity(this);
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar