终于到了 cocos2d 游戏开发的尽头,为了得到这个,我将 totalScore 发送到下一个 gameover.class 活动,如果它是高的并且想要显示分数和玩家姓名,则将其设置为高分。我已经这样做了,但是一旦游戏结束,我就无法进行 gameover.class 活动,不知道我哪里出错了。请帮我
这是我的游戏层(第一个活动)
if (spriteCounter<=0)
{
Intent mainScore = new Intent(CCDirector.sharedDirector().getActivity(), GameOver.class);
mainScore.putExtra("totalscore", countScore);
CCDirector.sharedDirector().getActivity().startActivity(mainScore);
System.out.println("------------");
CCDirector.sharedDirector().getActivity().finish();
}
gameover.class(第二个活动)
public class GameOver extends MainActivity {
ImageView playagain, home;
String[] columns;
int Score = 0;
String TOTALSCORE = "score";
String PLAYERNAME = "playername";
SQLiteDatabase db;
SharedPreferences sharedPreference = CCDirector.sharedDirector()
.getActivity().getSharedPreferences("sharedPreference", 0);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gameover);
int totalscore = getIntent().getIntExtra("totalscore", -1);
SharedPreferences sharedPreference = CCDirector.sharedDirector()
.getActivity().getSharedPreferences("sharedPreference", 0);
long temp_totalscore = (long) totalscore;
try {
String bp_totalscore = sharedPreference.getString(TOTALSCORE, null);
String bp_playername = sharedPreference.getString(PLAYERNAME, null);
if (totalscore > Integer.parseInt(bp_totalscore)) {
showSettingsDialog(temp_totalscore);
}
} catch (Exception e) {
showSettingsDialog(temp_totalscore);
}
intiatizeviews();
viewlisteners();
}
private void showSettingsDialog(long totalscore) {
EnterHighscore dialog = new EnterHighscore(this, totalscore);
dialog.show();
}
private void intiatizeviews() {
playagain = (ImageView) findViewById(R.id.playagainimageView);
home = (ImageView) findViewById(R.id.homeimageView);
}