Skip to content

Instantly share code, notes, and snippets.

@seal308
Created July 2, 2016 14:31
Show Gist options
  • Select an option

  • Save seal308/2e1f71337cb82cc16af1b4b7fee7237c to your computer and use it in GitHub Desktop.

Select an option

Save seal308/2e1f71337cb82cc16af1b4b7fee7237c to your computer and use it in GitHub Desktop.
exerpt of thread in memory game
myHandler = new Handler() {
public void handleMessage(Message msg){
super.handleMessage(msg);
if(playSequence){
button1.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
button2.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
button3.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
button4.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
if (setDefault)
{
button1.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
button2.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
button3.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
button4.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
}
else
{
switch(sequenceToCopy[elementToPlay]){
case 1:
button1.startAnimation(wobble);
button1.setBackgroundColor(Color.RED);
// play a sound
soundPool.play(sample1, 1, 1, 0, 0, 1);
break;
case 2:
button2.startAnimation(wobble);
button2.setBackgroundColor(Color.BLUE);
// play a sound
soundPool.play(sample2, 1, 1, 0, 0, 1);
break;
case 3:
button3.startAnimation(wobble);
button3.setBackgroundColor(Color.YELLOW);
// play a sound
soundPool.play(sample3, 1, 1, 0, 0, 1);
break;
case 4:
button4.startAnimation(wobble);
button4.setBackgroundColor(Color.GREEN);
// play a sound
soundPool.play(sample4, 1, 1, 0, 0, 1);
break;
case 5:
button1.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
button2.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
button3.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
button4.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.btn_default));
break;
}
}
if (setDefault)
{
setDefault = false;
sequenceFinished();
}
else
{
elementToPlay++;
if (elementToPlay == difficultyLevel)
{
setDefault = true;
}
}
}
myHandler.sendEmptyMessageDelayed(0,900);
}
}; //end of thread
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment