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

2012/4/14

Can somebody explain me how I can make a hiscore

1
2
3
4
danpost danpost

2012/4/15

#
All you need now is an act() method to check to see if the game is over (100 points?).
public void act()
{
    if (counter.getValue() >= 100) gameOver();
}
SPower SPower

2012/4/15

#
Just put that if statement in the act() method of BackGround. And you can remove the 'private boolean gameOver' line and then you must remove the 'gameOver = true' line of gameOver(), because you don't use it. After that: if there is an error, and it uses the gameOver boolean, just remove the line.
danpost danpost

2012/4/15

#
@martijn13039, in the code you last posted, your prepare method is RE-creating objects (which is something I do not think you want to do). Change the method like so:
public void prepare()
{
    counter = new Counter();
    user = new concierge(counter);
    addObject(counter, 54, 23);
    addObject(user, 120, 80);
}
Although a lot of this can be done in the variable declaration section as
private Counter counter = new Counter();
private consierge user = new consierge(counter);
private Saver saver = new Saver();
private ScoreBoard board;
Then all you would have to do is add the objects to the world. The scoreboard was not initialized because you will do that later when you have a score to put in it. Remember: if you do change your declarations to initialize the variables, remove the assignments in the code.
danpost danpost

2012/4/15

#
I was mainly comparing lines 6 and 7 with lines 33 and 34. Both lines 6 and 33 each create a seperate Counter object, one called 'Counter' and the other 'counter'. Along the same lines (of thought), lines 7 and 34 both create a seperate concierge object, one called 'user' and the other 'concierge'. Create your object once, and stick with the name you named it (unless you have more than one of that type object to place in your world). One more thing, standard Java naming convention: method and variable names begin with lowercase letters and class names begin with uppercase letters (and static final variables are all uppercase). Java is case sensitive, so 'Counter' is not the same as 'counter'.
martijn13039 martijn13039

2012/4/15

#
I will thank you all so mutch its working great now. thank you martijn
danpost danpost

2012/4/15

#
You will still need the boolean gameOver. 1) declare it with 'private boolean gameOver = false;' 2) change the 'if' in your act() method to 'if (counter.getValue() >= 100 && !gameOver)' 3) make sure the statement 'gameOver = true;' is in the gameOver() method @SPower, without the boolean, act() will call gameOver() repeatedly (not wanted)
martijn13039 martijn13039

2012/4/15

#
oke thx for al the great help
You need to login to post a reply.
1
2
3
4