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
|
package com.helmi.realquiz;
import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.widget.*;
import java.util.Random;
public class MainActivity extends Activity implements View.OnTouchListener{
int a=0;
String reponse="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//int nbvies=5,choixdesc;
((TextView) findViewById(R.id.question)).setText("Quel Pokémon évolue en Tarpaud ?");
((Button) findViewById(R.id.rep1)).setText("Ptitard");
((Button) findViewById(R.id.rep2)).setText("Tetarte");
((Button) findViewById(R.id.rep3)).setText("Tartard");
((Button) findViewById(R.id.rep4)).setText("Tiplouf");
((Button) findViewById(R.id.rep1)).setOnTouchListener(this);
((Button) findViewById(R.id.rep2)).setOnTouchListener(this);
((Button) findViewById(R.id.rep3)).setOnTouchListener(this);
((Button) findViewById(R.id.rep4)).setOnTouchListener(this);
reponse="Tetarte";
Thread myThread = new Thread(myRunnable);
myThread.start();
this.myRunnable.run();
a=0;
((TextView) findViewById(R.id.question)).setText("Quel Pokémon évolue en Ronflex ?");
((Button) findViewById(R.id.rep1)).setText("Goinfrex");
((Button) findViewById(R.id.rep2)).setText("Tetarte");
((Button) findViewById(R.id.rep3)).setText("Tartard");
((Button) findViewById(R.id.rep4)).setText("Tiplouf");
reponse="goinfrex";
myThread = new Thread(myRunnable);
myThread.start();
}
Runnable myRunnable = new Runnable() {
@Override
public void run() {
while (a == 0) {
synchronized (this){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
};
@Override
public boolean onTouch(View v, MotionEvent event) {
TextView text = new TextView(this);
a=v.getId();
String b = (String) ((Button) findViewById(a)).getText();
if (reponse.equalsIgnoreCase(b))
{
text.setText("Trouvé");
setContentView(text);
}
else
{
text.setText("Loupé");
setContentView(text);
}
return true;
}
} |