I am making a knowledge based game , in which user participate and if they win and get their rank within criteria they earn gems , coins etc.
Example- A game in which their are 500 participants , and predefined Prize Distribution is Like…
Rank 1 gets 50000 coins
Rank 2 gets 40000 coins
Rank 3 to 50 gets 20000 coins
Rank 51 to 200 gets 5000 coins
Rank 201 to 500 gets 1000coins
If User plays the game and suppose he gets the rank 81 . So how can I check the distribution and award him the prize i.e, 5000 coins.
Can i use Hashmap to create some kind of key-value pair ..as shown below..
HashMap<Integer, Integer> distribution = new HashMap<>();
distribution.add(1,50000);
.
.
.
distribution.add(500,1000);
Any suggestions will boost my work.
2
Answers
I would recommend you to make a Range wrapper class and lookup the value for a key in the range;
This might help: https://stackoverflow.com/a/1314708/10052779
Well you could do a few loops if you want to use HashMaps.
and tada you are done! However, unless you want it to run every single time, I would make distribution a static variable so you only have to run it once and it will stay for every run after that.