I'm coding the game "Simon", and I'm having some trouble figuring out how to use runnables and handlers. This is for the part of the game where the colors light up in a sequence pattern, right before the player has to press the buttons.
This is the code I have so far:
Handler handler = new Handler();
Runnable g = new Runnable() {
@Override
public void run() {
setBtnBackGround(oldColors[0], 10, mButtons[0]);
}
};
Runnable r = new Runnable() {
@Override
public void run() {
setBtnBackGround(oldColors[1], 10, mButtons[1]);
}
};
Runnable y = new Runnable() {
@Override
public void run() {
setBtnBackGround(oldColors[2], 10, mButtons[2]);
}
};
Runnable b = new Runnable() {
@Override
public void run() {
setBtnBackGround(oldColors[3], 10, mButtons[3]);
}
};
Also:
for (int i = 0; i < mGame.getLevel(); i++) {
int color = colors.get(i);
setBtnBackGround(newColors[color], 10, mButtons[color]);
if (color == 0) {
handler.postDelayed(g, 1000);
} else if (color == 1) {
handler.postDelayed(r, 1000);
} else if (color == 2) {
handler.postDelayed(b, 1000);
} else {
handler.postDelayed(y, 1000);
}
}
The buttons all light up at the same time, since, I guess, they're all placed one after another on the "message sequence"? How would I use runnables/handles to space apart the light-ups?
Thanks so much guys!