[안드로이드게임] 교육용 숫자, 알파벳 순수대로 누르기게임
package com.mrgame.oneto_50;
import java.util.Random;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
public static int result_main = 0;
ImageView ivs[] = new ImageView[12];
int count = 0;
ProgressBar pb;
TextView pbtotv;
int numIv[] = { R.drawable.num01, R.drawable.num02, R.drawable.num03,
R.drawable.num04, R.drawable.num05, R.drawable.num06,
R.drawable.num07, R.drawable.num08, R.drawable.num09,
R.drawable.num10, R.drawable.num11, R.drawable.num12 };
int seconds;
boolean isPlay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int nums[] = new int[12];
Random rnd = new Random();
for (int i = 0; i < 12; i++) {
nums[i] = rnd.nextInt(12);
for (int j = 0; j < i; j++) {
if (nums[i] == nums[j]) {
i--;
break;
}
}
}
for (int i = 0; i < 12; i++) {
ivs[i] = (ImageView) findViewById(R.id.num01 + i);
ivs[i].setImageResource(numIv[nums[i]]);
ivs[i].setOnClickListener(listener);
ivs[i].setTag(nums[i]);
}
pb = (ProgressBar) findViewById(R.id.pb);
pbtotv=(TextView) findViewById(R.id.pbtotv);
startTimer();
}
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String s = v.getTag().toString();
int n = Integer.parseInt(s);
if (n == count) {
count++;
((ImageView) v).setVisibility(View.INVISIBLE);
}
if (count >= 12) {
isPlay = false;
result_main = seconds;
Intent intent = new Intent(MainActivity.this,
SecondActivity.class);
startActivity(intent);
}
}
};
public void startTimer() {
seconds = 30;
isPlay = true;
new Thread(new Runnable() {
@Override
public void run() {
while (seconds >= 0 && isPlay) {
runOnUiThread(new Runnable() {
public void run() {
pb.setProgress(seconds);
pbtotv.setText(seconds+"");
}
});
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
seconds--;
}
if (seconds <= 0) {
runOnUiThread(new Runnable() {
public void run() {
Intent intent = new Intent(MainActivity.this,
SecondActivity.class);
startActivity(intent);
}
});
}
}
}).start();
}
}
교육용입니다.ㅋ 필요하신분들은 쓰세용ㅋㅋㅋ
첨부파일
댓글 1개
게시판 목록
앱개발
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 728 | Hybrid | 4년 전 | 1561 | ||
| 727 | Hybrid | 4년 전 | 3757 | ||
| 726 | Hybrid |
|
4년 전 | 1892 | |
| 725 | Android |
앱개발자가되고싶다
|
4년 전 | 2973 | |
| 724 | IOS | 4년 전 | 1171 | ||
| 723 | Hybrid | 4년 전 | 1613 | ||
| 722 | 기타 | 4년 전 | 2776 | ||
| 721 | 4년 전 | 1808 | |||
| 720 | 4년 전 | 2349 | |||
| 719 | 4년 전 | 1825 | |||
| 718 | 4년 전 | 1046 | |||
| 717 | 4년 전 | 1321 | |||
| 716 | 4년 전 | 1564 | |||
| 715 | 4년 전 | 2159 | |||
| 714 | 4년 전 | 1508 | |||
| 713 | 4년 전 | 1737 | |||
| 712 | 4년 전 | 1132 | |||
| 711 | 4년 전 | 1131 | |||
| 710 | 4년 전 | 1210 | |||
| 709 | 4년 전 | 1189 | |||
| 708 | 4년 전 | 1741 | |||
| 707 | 4년 전 | 1155 | |||
| 706 | 4년 전 | 1200 | |||
| 705 | 4년 전 | 817 | |||
| 704 | 4년 전 | 1127 | |||
| 703 | 4년 전 | 2357 | |||
| 702 | 4년 전 | 1156 | |||
| 701 | 5년 전 | 1941 | |||
| 700 | 5년 전 | 1926 | |||
| 699 | 5년 전 | 1198 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기