Created
July 2, 2016 14:31
-
-
Save seal308/2e1f71337cb82cc16af1b4b7fee7237c to your computer and use it in GitHub Desktop.
exerpt of thread in memory game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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