3 つの質問 / レベルのクイズを作成しています。私の問題は、何を実装するか、正しい答えを数える方法をコーディングするかわからないことです。たとえば、ユーザーが正しい答え(ボタン)をクリックすると、レベル3に達するまでカウントされ、追加されます。彼がゲームを終了すると、私の complete.class がポップアップし、ユーザーが highscore(button) をクリックするとテキストが自動的に my highscore.class に設定されるボタンがあります。
levelone.class
public class EasyOne extends Activity {
ImageButton a, b, c;
Intent intent ;
CountDownTimer cdt;
TextView timer;
MediaPlayer player;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.easyone);
a = (ImageButton) findViewById(R.id.ib_a);
b = (ImageButton) findViewById(R.id.ib_b);
c = (ImageButton) findViewById(R.id.ib_c);
timer = (TextView) findViewById(R.id.tv_timer);
cdt = new CountDownTimer(5000,1000) {
@Override
public void onTick(long millisUntilFinished) {
timer.setText("seconds remaining: " + millisUntilFinished / 1000);
}
@Override
public void onFinish() {
timer.setText("TIMES UP!");
intent = new Intent(getApplicationContext(),TimesUp.class);
startActivity(intent);
}
};
intent = new Intent(getApplicationContext(),ChoiceTwo.class);
a.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(intent);
cdt.cancel();
Intent intent = new Intent(getApplicationContext(),ChoiceTwo.class);
startActivity(intent);
}
});
cdt.start();
}
}
complete.class
public class complete extends Activity {
Button highscore;
String highestScore;
int score;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// TODO Auto-generated method stub
highscore = (Button) findViewById(R.id.save);
highscore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
if (score > preferences.getInt("score", 0)) {
preferences.edit().putInt("score", score).commit();
}
Intent showHighScore = new Intent(MainActivity.this, highscore.class);
showHighScore.putExtra("current_score", score);
startActivity(showHighScore);
}
});
}
}
ハイスコア.クラス
public class highscore extends Activity {
Button back;
TextView highScore;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.highscore);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
int currentScore = getIntent().getIntExtra("current_score", 0);
highScore = (TextView) findViewById(R.id.tv_highscore);
highScore.setText(currentScore + " / " + preferences.getInt("score", 0));
int highestScore = -1;
//Now use this score variable to set anywhere.
Bundle extras = getIntent().getExtras();
if (extras != null) {
highestScore = extras.getInt("score");
}
back = (Button) findViewById(R.id.btn_back);
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Back",
Toast.LENGTH_SHORT).show();
}
});
// TODO Auto-generated method stub
}
}