java - High Score in Android -
i totally broke high score leaderboard in android... want display top 5 high scores in game.. how can it... have scores , names stored in database... should next ?
i have code sorting of scores...
collections.sort(scorelist); for(int i=0; i<5;i++){ highscorelist.add(scorelist.get(i)); } return highscorelist; }
i looking possiblity of sorting descending , getting first 5 records.. question, if that's happen, how can compare score if belongs high score?
like tobiel said if data stored in database query better. however, if need in code should modify collection sort.
if in scorelist have collection of score objects can compare scores this:
collections.sort(scorelist, new comparator<score>() { @override public int compare(score score1, score score2){ if(score1.getscore() < score2.getscore()) return -1; else if(score1.getscore() > score2.getscore()) return 1; else return 0; } });
then when execute loop organized highest scores.
Comments
Post a Comment