Проблема с системой лидеров (High Score) - PullRequest
0 голосов
/ 29 мая 2019

В моей java-игре есть класс лидеров, но он не работает так, как я хочу.У меня есть 3 балла, которые отображаются при нажатии на кнопку списка лидеров, 1-й, 2-й и 3-й.У меня проблема в том, что всякий раз, когда я получаю балл, который должен заменить 2-й балл, он не изменит 3-й балл.Так, например:

1st = 10
2nd = 8
3rd = 5

если я наберу 9 в игре, это будет выглядеть так:

1st = 10
2nd = 9
3rd = 5

Я хочу, чтобы 3-й счет был заменен исходным 2-м счетом.так что это будет выглядеть так:

1st = 10
2nd = 9
3rd = 8

Любая помощь в том, как я могу достичь этого, будет принята с благодарностью!

Мой код:

 TextView tvScore, tvPersonalBest, tvSecondBest, tvThirdBest;

 int score = getIntent().getExtras().getInt("score");
        SharedPreferences pref = getSharedPreferences("MyPref",0);

        int scoreSP = pref.getInt("scoreSP",0);
        SharedPreferences.Editor editor = pref.edit();

        int scoreSB = pref.getInt("scoreSB",0);
        SharedPreferences.Editor editorr = pref.edit();

        int scoreTB = pref.getInt("scoreTB",0);
        SharedPreferences.Editor editorrr = pref.edit();

        if(score > scoreSP){
            scoreSP = score;
            editor.putInt("scoreSP", scoreSP);
            editor.commit();
        }
        if(score > scoreTB && score < scoreSP){
            scoreSB = score;
            editorr.putInt("scoreSB", scoreSB);
            editorr.commit();
        }
        if(score < scoreSB && score > scoreTB){
            scoreTB = score;
            editorrr.putInt("scoreTB", scoreTB);
            editorrr.commit();
        }
        tvScore = findViewById(R.id.tvScore);
        tvPersonalBest = findViewById(R.id.tvPersonalBest);
        tvSecondBest = findViewById(R.id.secondBest);
        tvThirdBest = findViewById(R.id.thirdBest);
        tvScore.setText(""+score);
        tvPersonalBest.setText(""+scoreSP);
        tvSecondBest.setText(""+scoreSB);
        tvThirdBest.setText(""+scoreTB);


    }
...