public class MoleActivity extends Activity {
private Handler mHandler = null; // 메시지를 전달할 핸들러
int mScore = 0; // 점수
int mTime = 30; // 제한시간
int[] imgValue = new int[9];
ImageButton[] imgMole = new ImageButton[9]; // 두더지 새끼들
@Override
public void onCreate(Bundle savedInstanceState) { //액티비티가 실행되면 onCreate 실행됨
super.onCreate(savedInstanceState); // 부모 클래스의 onCreate 실행됨
setContentView(R.layout.main); //액티비티의 콘텐츠뷰(레이아웃)을 main으로 설정
Button btnReset = (Button)findViewById(R.id.btnReset); // findViewById 말 그대로 아이디로 객체를 찾음. (button)형식으로 반환
final TextView txtScore = (TextView)findViewById(R.id.txtScore); //점수를 보여줄 텍스트 뷰
final TextView txtTime = (TextView)findViewById(R.id.txtTime); // 시간을 보여줄 텍스트뷰
imgMole[0] = (ImageButton)findViewById(R.id.imageButton1); // 두더지새끼들도 findviewbyid로 찾아놓음
imgMole[1] = (ImageButton)findViewById(R.id.imageButton2);
imgMole[2] = (ImageButton)findViewById(R.id.imageButton3);
imgMole[3] = (ImageButton)findViewById(R.id.imageButton4);
imgMole[4] = (ImageButton)findViewById(R.id.imageButton5);
imgMole[5] = (ImageButton)findViewById(R.id.imageButton6);
imgMole[6] = (ImageButton)findViewById(R.id.imageButton7);
imgMole[7] = (ImageButton)findViewById(R.id.imageButton8);
imgMole[8] = (ImageButton)findViewById(R.id.imageButton9);
btnReset.setOnClickListener(new View.OnClickListener(){ // 리셋 버튼에 온클릭리스너 만듬 (미친새끼 이걸 왜 이렇게 하냐)
public void onClick(View v){
mScore = 0;
mTime = 30;
mHandler.sendEmptyMessageDelayed(0, 1000); //클릭하면 빈 메시지 보냄
}
}); //온클릭리스너 끝
for(int i=0; i<9; i++){
final int arrayI = i;
imgMole[i].setOnClickListener(new View.OnClickListener(){ //두더지 새끼들도 온클릭 리스너 박음
public void onClick(View v){ //클릭하면
imgMole[arrayI].setImageResource(R.drawable.none); // 이미지를 바꾸고
if(imgValue[arrayI] == 1){ // 두더지 새끼가 나온 상태면...
mScore++; //점수 추가하고
imgValue[arrayI] =0; //
} //온클릭 끝
} //온클릭리스너 생성자 함수 재정의
}); // imgMole[i].setOnClickListener 끝
} // for문 끝
mHandler = new Handler() { // 메시지 받는 핸들러
public void handleMessage(Message msg) {
txtTime.setText("시간:" + mTime); //시간이랑 점수 텍스트뷰 내용 바꿈 바꿈 (invalidate인가? 갱신 해줘야 뜬다. 병신아.)
txtScore.setText("점수:" + mScore);
if(mTime== 0){
Toast toast = Toast.makeText(getBaseContext(),
"종료", 100000);
toast.show(); //토스트 띄움
return;
} // if(mTime== 0) 끝
mHandler.sendEmptyMessageDelayed(0, 1000); // 1초마다 핸들러 쏴줌. 미친 새끼 쓰레드는 어따 팔아치웠냐
mTime--; // 1초 감소
double rValue = java.lang.Math.random();
int selectedIndex = (int)(rValue * 10);
if(selectedIndex == 9)
selectedIndex = 4;
for(int i=0; i<9;i++){ // 두더지 새끼들
imgValue[i] = 0;
imgMole[i].setImageResource(R.drawable.none); // 다 땅속에 박음
} // for문 종료
imgValue[selectedIndex] = 1;
imgMole[selectedIndex].setImageResource(R.drawable.mole);
} // public void handleMessage(Message msg) 끝
}; // 핸들러 선언 끝
} // onCreate 끝
} // MoleActivity 끝
[ㅇㅇ은(는) 어깨가 으쓱 거렸다]
아무대나 스레드 타령하는거보니 너도 수준이 보이는구나
뭘 아무대나야. 점마는 1개 액티비티 내부에서 핸들러로 메시지 쏴대자나
와 감사합니다 형님.. 이거보고 피피티를 만들어서 발표하면 교수님이 피피티 발로차거나 절 발로 찰까요?
감사합니다 형님 ..^^ 모르는부분은 직접 찾아볼께요
그대로 가면 개까일거다. 근데 안드로이드 모르는 교수는 우와거릴듯...
근데 자바 수업일거자나....그럼 100퍼 왜 쓰레드 안쓰고 메시지 핸들러 썼냐고 물어볼 거 같은데....내는 모르겠다.
멍청이;;; 스레드는 cpu 코어 여러개 활용하자는거지;;;;
선생질 할 생각말고 니 공부나 해라;;;;;;;;;
ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ 아 졸 웃기다