This site requires JavaScript, please enable it in your browser!
Greenfoot back
Nosson1459
Nosson1459 wrote ...

2017/1/30

High Scores

Nosson1459 Nosson1459

2017/1/30

#
How can I use the getTop() and getNearby() methods to display the high scores? I want to show all the high scores in descending order of score. I have a randomly generated score to a user for a test, and the user will get a new score when the newly generated score is higher than their current score. I think all this works but I want to display all the users with their scores and you should be able to scroll through the list, or at least just look at the top few with getTop(7) or something. The code i have right now is:
UserInfo myInfo = UserInfo.getMyInfo();
Random myRandom = new Random();
int newScore = myRandom.nextInt(2500) + 1;
if (newScore > myInfo.getScore()) myInfo.setScore(newScore);
GreenfootImage scoreText = new GreenfootImage("Score: " + myInfo.getScore(), 36, null, null);
getBackground().drawImage(scoreText, (getWidth() / 2) - (scoreText.getWidth() / 2), (int) getHeight() - scoreText.getHeight());
I know to (or think I should) use 'myInfo.getTop(0);' but I don't know what to do with that.
danpost danpost

2017/1/30

#
There is a 'ScoreBoard' class that is provided with the greenfoot download that you can "Edit>Import class..." from the menubar that creates an Actor object that displays top(n) and near(n) scores of the UserInfo data for a scenario. You just need to make sure of the availability of the UserInfo data.
Nosson1459 Nosson1459

2017/1/30

#
Thanks, I'll look at it.
Nosson1459 Nosson1459

2017/1/30

#
I never figured out how to use removeObject not in that class. I can do removeObject(this) but how would I remove the scoreBoard from the world?
danpost danpost

2017/1/30

#
Nosson1459 wrote...
I never figured out how to use removeObject not in that class. I can do removeObject(this) but how would I remove the scoreBoard from the world?
From your subclass of World that the scoreboard is in:
removeObjects(getObjects(ScoreBoard.class));
is one way, if you do not have a reference to the ScoreBoard actor. If you did and it was in a field called 'scoreboard', then:
removeObject(scoreboard);
would be sufficient. From an Actor subclass, you would need 'getWorld().' before any 'getObjects', 'removeObjects' or 'removeObject' call (the World class method calls).
Nosson1459 Nosson1459

2017/1/30

#
Oh I didn't try this in a while and I didn't understand that I needed a field, just now I was about to use it when I noticed that I might need a field because I didn't know what else to put in so I asked.I knew I can't just put in ScoreBoard because that can be talking about any ScoreBoard but when I tried this a while ago (previous year) I didn't notice this BUT I did know about the removeObjects(...
Nosson1459 Nosson1459

2017/2/1

#
Nosson1459 wrote...
I want to display all the users with their scores and you should be able to scroll through the list
With the ScoreBoard class it doesn't scroll it just shows the top 7 and the 7 near me.
Nosson1459 Nosson1459

2017/2/2

#
How would I make a score board that you can see all the users and their scores even if they are not all on the screen at once?
Super_Hippo Super_Hippo

2017/2/2

#
Make an unbounded world and just add all. Then you need a way to scroll down, so move all objects upwards. You can also change the scoreboard, so more results are fitting on the screen. Btw, for testing purposes, you can check the highscore table in Greenfoot, too. Press Ctrl+Shift+P to change to name, run the scenario to get the score for this "player", then change the name again and so on. This way, you can fill the highscore table offline to check how it looks and if it is working.
Nosson1459 Nosson1459

2017/2/3

#
Super_Hippo wrote...
Make an unbounded world and just add all. Then you need a way to scroll down, so move all objects upwards. You can also change the scoreboard, so more results are fitting on the screen.
I guess so, but I was looking for something like the way "bourne" did it, which I guess I can just look at his code.
Btw, for testing purposes, you can check the highscore table in Greenfoot, too. Press Ctrl+Shift+P to change to name, run the scenario to get the score for this "player", then change the name again and so on. This way, you can fill the highscore table offline to check how it looks and if it is working.
I did this already, that's how I knew it doesn't scroll (when you download the scenario you can see that the storage file is full).
You need to login to post a reply.