I'm doing this using handler.postdelayed but whenever i start clicking on tiles postdelayed doesn't work sometimes it comes fast and sometimes slow. Here is the code private Handler mhandler = new Handler();
private Runnable mcontinue = new Runnable() {
@Override
public void run() {
//row5
RockLocationRow5 = RockLocationRow4;
setRockLocation(RockLocationRow5, 5);
//row4
RockLocationRow4 = RockLocationRow3;
setRockLocation(RockLocationRow4, 4);
//row3
RockLocationRow3 = RockLocationRow2;
setRockLocation(RockLocationRow3, 3);
//row2
RockLocationRow2 = RockLocationRow1;
setRockLocation(RockLocationRow2, 2);
//row1
RockLocationRow1 = r.nextInt(3) + 1;
setRockLocation(RockLocationRow1, 1);
mhandler.postDelayed(this, 3000);
}
};
I'm calling it in initgame function whenever the game starts and if i click on any tile I'm also calling this Runnable their
iv_13.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(RockLocationRow1 == 3){
mcontinue.run();
}
else{
//endGame();
}
}
});
or is their anything else that I can use?? I'm a beginner...
this is how RockLocationRow is initialized
//row3
RockLocationRow3 = 1;
iv_31.setImageResource(tapImage);
//row2
RockLocationRow2 = r.nextInt(3) + 1;
setRockLocation(RockLocationRow2, 2);
//row1
RockLocationRow1 = r.nextInt(3) + 1;
setRockLocation(RockLocationRow1, 1);
and this is setRockLocation
private void setRockLocation(int place, int row){
if(row == 1){
iv_11.setImageResource(emptyImage);
iv_12.setImageResource(emptyImage);
iv_13.setImageResource(emptyImage);
switch (place) {
case 1:
iv_11.setImageResource(tapImage);
break;
case 2:
iv_12.setImageResource(tapImage);
break;
case 3:
iv_13.setImageResource(tapImage);
break;
}
}
same for row 2,3,4 and 5