如果分数不应该超过Android Studio高分的两倍

时间:2018-09-23 09:12:56

标签: java android

我有5个最佳分数将显示在高分活动中,但如果得分相同,则该分数将重复出现,例如第1场比赛我获得2分,下一场比赛我也得到2分。高分活动需要刷新每场比赛,然后将安排减少,也需要分数不会多余。

hsv = findViewById(R.id.highscoreview);

SharedPreferences setting = getSharedPreferences("GAME_DATA", Context.MODE_PRIVATE);

int highScore = setting.getInt("HIGH_SCORE",0);

best1 = setting.getInt("BEST1:", 0);
best2 = setting.getInt("BEST2:", 0);
best3 = setting.getInt("BEST3:", 0);
best4 = setting.getInt("BEST4:", 0);
best5 = setting.getInt("BEST5:", 0);

if (highScore > best5){
    best5 = highScore;
    // save
    SharedPreferences.Editor editor = setting.edit();
    editor.putInt("BEST5:",best5);
    editor.commit();

}
if (highScore > best4) {
    int temp = best4;
    best4 = highScore;
    best5 = temp;
    // save
    SharedPreferences.Editor editor = setting.edit();
    editor.putInt("BEST5:", best5);
    editor.putInt("BEST4:", best4);
    editor.commit();
}
if (highScore > best3){
    int temp = best3;
    best3 = highScore;
    best4 = temp;
    // save
    SharedPreferences.Editor editor = setting.edit();
    editor.putInt("BEST4:",best4);
    editor.putInt("BEST3:",best3);
    editor.commit();
}
if (highScore > best2){
    int temp = best2;
    best2 = highScore;
    best3 = temp;
    // save
    SharedPreferences.Editor editor = setting.edit();
    editor.putInt("BEST3:",best3);
    editor.putInt("BEST2:",best2);
    editor.commit();
}

if (highScore > best1) {
    int temp = best1;
    best1 = highScore;
    best2 = temp;
    // save
    SharedPreferences.Editor editor = setting.edit();
    editor.putInt("BEST2:", best2);
    editor.putInt("BEST1:", best1);
    editor.commit();

}

hsv.setText(
    "BEST1:" + best1 + "\n" +
    "BEST2:" + best2 + "\n" +
    "BEST3:" + best3 + "\n" +
    "BEST4:" + best4 + "\n" +
    "BEST5:" + best5);

0 个答案:

没有答案