こんにちは、Android ゲーム開発の初心者です。私のこの Android ゲームの正しいロジック フローについてお聞きしたいと思います。これが私のゲームです。これは、ユーザーが正しい色を選択する必要がある非常に単純なゲームです。ゲームは3ステージ。各ステージには、10 の質問があります。各質問には、30 秒のタイマーがあります。もちろん、質問と選択肢をランダム化する必要があります。ユーザーが正しい色を選択すると、次の質問に進みます。ただし、ユーザーが間違った色を選択した場合、選択できるのは 3 回の試行のみです。3 回目の試行に達すると、ゲームは終了し、 TRY AGAINボタンが表示されます。
ここに私が試したコードがあります:
// I created a custom countdown timer c/o Say
counter = new MyCount(30000,1000);
counter.start();
// Call for correct object
getCorrectObject();
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.pause:
if(mLastResourceId == R.drawable.pause){
pause.setImageResource(R.drawable.resume);
mLastResourceId = R.drawable.resume;
counter.cancel();
} else if (mLastResourceId == R.drawable.resume) {
pause.setImageResource(R.drawable.pause);
mLastResourceId = R.drawable.pause;
counter = new MyCount(s1,1000);
counter.start();
}
break;
}
public class MyCount extends CountDownTimer
{
public MyCount(long millisInFuture, long countDownInterval)
{
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish()
{
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
}
TextView tx = (TextView) findViewById(R.id.timer);
@Override
public void onTick(long millisUntilFinished)
{
s1 = millisUntilFinished;
tx.setText("" + millisUntilFinished / 1000);
}
}
私が考えているのは、タイマーが終了せずにユーザーが正しい答えを選択した場合、タイマーを強制的に終了させるために onTick メソッドに何を入れるべきですか? そして、私が直面しているトリッキーな部分の 1 つは、選択肢またはオブジェクトのランダム化です。
これも私がこれまでに試したことです:
private void getCorrectObject() {
// TODO Auto-generated method stub
List<Integer> objects = new ArrayList<Integer>();
objects.add(1);
objects.add(2);
objects.add(3);
objects.add(4);
objects.add(5);
objects.add(6);
objects.add(7);
Collections.shuffle(objects);
int correctObject = objects.get(0);
Log.d("test", String.valueOf(correctObject));
switch(correctObject)
{
case 1:
bObjectCorrect.setImageResource(R.drawable.tree1);
bObjectCorrect.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_1.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 2:
bObject1.setImageResource(R.drawable.tree1);
bObject1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_1.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 3:
bObject2.setImageResource(R.drawable.tree1);
bObject2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_1.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 4:
bObject3.setImageResource(R.drawable.tree1);
bObject3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_1.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 5:
bObject4.setImageResource(R.drawable.tree1);
bObject4.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_1.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 6:
bObject5.setImageResource(R.drawable.tree1);
bObject5.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_1.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 7:
bObject6.setImageResource(R.drawable.tree1);
bObject6.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_1.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
}
}
更新:もう 1 つのことは、3 回の試行のために while ループをどこに置くべきか混乱していることです。
// I will put 3 trials logic here
while(trial <= 3){
trial++;
switch(correctObject)
{
case 1:
bObjectCorrect.setImageResource(R.drawable.stage1_1_object1);
bObjectCorrect.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_2.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 2:
bObject1.setImageResource(R.drawable.stage1_1_object1);
bObject1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_2.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 3:
bObject2.setImageResource(R.drawable.stage1_1_object1);
bObject2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_2.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 4:
bObject3.setImageResource(R.drawable.stage1_1_object1);
bObject3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_2.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 5:
bObject4.setImageResource(R.drawable.stage1_1_object1);
bObject4.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_2.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 6:
bObject5.setImageResource(R.drawable.stage1_1_object1);
bObject5.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_2.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 7:
bObject6.setImageResource(R.drawable.stage1_1_object1);
bObject6.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_2.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 8:
bObject7.setImageResource(R.drawable.stage1_1_object1);
bObject7.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_2.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
case 9:
bObject8.setImageResource(R.drawable.stage1_1_object1);
bObject8.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), Stage1_2.class);
startActivity(i);
new Thread(){
public void run(){
MediaPlayer mp = MediaPlayer.create(Stage1_2.this, R.raw.brown);
mp.start();
}
}.start();
finish();
}
});
break;
} // Last of switch statement
if(trial == 3){
new AlertDialog.Builder(this)
.setTitle("Game Over")
.setMessage("Sorry you reached your 3rd trial")
.setPositiveButton("Try Again?", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(Stage1_2.this, Stage1_1.class);
startActivity(i);
}
})
.setNegativeButton("Back to Menu", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(Stage1_2.this, ShapingColors.class);
startActivity(i);
}
})
.show();
}
} // Last of while loop
あなたの提案を聞きたいです。あなたからのどんな助けも本当に感謝しています。前もって感謝します!