String [] preguntas1 ={"Mejor jugador del mundo ","Quien direje el Barsa"," donde se pone un penalti "};
String [] preguntas2 ={"dos y dos ","en que año estamos"," de donde se saca el corner "};
String [] respuestas1={"Messi","luis","punto"};
String [] respuestas2={"4","2016","esquina"};
TextView textoPregunta,textoPrueba;
EditText textoRespuesta;
Button botonComprobacion;
int nivel=1;
int totalAciertosNivel1=0;
int totalAciertosNivel2=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textoPregunta=(TextView) findViewById(R.id.textPreguntas);
textoRespuesta=(EditText) findViewById(R.id.textRespuestas);
textoPrueba=(TextView) findViewById(R.id.textprueba);
botonComprobacion=(Button) findViewById(R.id.buttonComprobar);
textoPregunta.setText(""+preguntas1[totalAciertosNivel1]);
botonComprobacion.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
comprobarNivel();
// textoPrueba.setText(""+totalAciertosNivel1 + " " + nivel);
}
});
}
public void comprobarNivel(){
switch (nivel) {
case 1:
if(totalAciertosNivel1==0){
textoPregunta.setText(""+preguntas1[totalAciertosNivel1]);
}
Nivel1();
break;
case 2:
if(totalAciertosNivel2==0){
textoPregunta.setText(""+preguntas2[totalAciertosNivel2]);
}
Nivel2();
break;
case 3:
textoPregunta.setText("Has completado el juego");
break;
}
}
public void Nivel1(){
if (textoRespuesta.getText().toString().equals(respuestas1[totalAciertosNivel1].toString())){
if(totalAciertosNivel1 <preguntas1.length){
totalAciertosNivel1++;
textoRespuesta.setText("");
if (totalAciertosNivel1 < preguntas1.length){
textoPregunta.setText(""+preguntas1[totalAciertosNivel1]);
}
}
Toast.makeText(getApplicationContext(), "Has acertado", Toast.LENGTH_SHORT).show();
}else{
textoRespuesta.setText("");
Toast.makeText(getApplicationContext(), "Has Fallado", Toast.LENGTH_SHORT).show();
}
if(totalAciertosNivel1==preguntas1.length){
nivel ++;
textoPregunta.setText(""+preguntas2[totalAciertosNivel2]);
}
textoPrueba.setText(""+totalAciertosNivel1 + " " + nivel + " "+ preguntas1.length);
}
public void Nivel2(){
if (textoRespuesta.getText().toString().equals(respuestas2[totalAciertosNivel2].toString())){
if(totalAciertosNivel2 <preguntas2.length){
totalAciertosNivel2++;
textoRespuesta.setText("");
if (totalAciertosNivel2 < preguntas2.length){
textoPregunta.setText(""+preguntas2[totalAciertosNivel2]);
}
}
Toast.makeText(getApplicationContext(), "Has acertado", Toast.LENGTH_SHORT).show();
}else{
textoRespuesta.setText("");
Toast.makeText(getApplicationContext(), "Has Fallado", Toast.LENGTH_SHORT).show();
}
if(totalAciertosNivel2==preguntas2.length){
nivel ++;
textoPregunta.setText("Has completado el ejerccio");
}
textoPrueba.setText(""+totalAciertosNivel1 + " " + nivel + " "+ preguntas1.length);
}