I am a beginner programmer on Android and I create my own game that adds from randomly generated numbers. the player's task is to guess the result by adding, by selecting 3 given numbers in which is the real result. Everything works fine but I would like the correct result every round was on another button so that the player does not realise that the correct result is on button number 1 and buttons 2 and 3 are false
private void startTimerThread() {
final Handler handler = new Handler();
los();
proba.setText("dodawanie");
c = Dodawanie(a, b);
Random liczba = new Random();
h = liczba.nextInt(5);
Toast.makeText(getApplicationContext(), String.valueOf(c), Toast.LENGTH_LONG).show();
Runnable runnable = new Runnable() {
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
handler.post(new Runnable() {
public void run() {
W1.setText(String.valueOf(c));
Wyb1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
p++;
l.setText(String.valueOf(p));
startTimerThread();
}
});
W2.setText(String.valueOf(l1));
Wyb2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Zle", Toast.LENGTH_LONG).show();
}
});
W3.setText(String.valueOf(l2));
Wyb3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Zle", Toast.LENGTH_LONG).show();
}
});
}
});
}
};
new Thread(runnable).start();
}
I tried to do it with the if and Class Random commands but sometimes did not give the correct result on the button
if(h==0||h==3) {
W1.setText(String.valueOf(c));
Wyb1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
p++;
l.setText(String.valueOf(p));
Do();
}
});
W2.setText(String.valueOf(l1));
Wyb2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Zle", Toast.LENGTH_LONG).show();
}
});
W3.setText(String.valueOf(l2));
Wyb3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Zle", Toast.LENGTH_LONG).show();
}
});
}
else if(h==1||h==4){
W2.setText(String.valueOf(c));
Wyb2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
p++;
l.setText(String.valueOf(p));
Do();
}
});
W1.setText(String.valueOf(l1));
Wyb1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Zle", Toast.LENGTH_LONG).show();
}
});
W3.setText(String.valueOf(l2));
Wyb3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Zle", Toast.LENGTH_LONG).show();
}
});
if(h==2||h==5)
{
W3.setText(String.valueOf(c));
Wyb3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
p++;
l.setText(String.valueOf(p));
Do();
}
});
W1.setText(String.valueOf(l1));
Wyb1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Zle", Toast.LENGTH_LONG).show();
}
});
W2.setText(String.valueOf(l2));
Wyb2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Zle", Toast.LENGTH_LONG).show();
}
});
}
Aucun commentaire:
Enregistrer un commentaire