[안드로이드게임] 교육용 숫자, 알파벳 순수대로 누르기게임 정보
[안드로이드게임] 교육용 숫자, 알파벳 순수대로 누르기게임본문
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();
}
}
교육용입니다.ㅋ 필요하신분들은 쓰세용ㅋㅋㅋ
0