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

2020/2/9

Highscore counter

minetruck minetruck

2020/2/9

#
Hi, I want to make a highscore counter. Is it possible to let the highscore wait in the secound round until it gets to the same score as the normal score counter. For example: First Round: 5 points on the score counter so 5 points is the new highscore, then second round only 3 points but still 5 points on the highscore. my problem is that when i reset the game the highscore counter still adds the points and doesnt "wait" until it has the same score as the score counter. so it would be in the secound round 8 points World code:
private Counter counter = new Counter("Score: ");
private static Counter counter1 = new Counter("Highscore: ");
Method:
public void isTouchingAsteroid(){
        counter.add(1);
        if (counter.getValue() == (counter1.getValue())){
             counter1.add(1);
        }
    }
i hope you understand what i mean thanks
danpost danpost

2020/2/9

#
What codes are you using to transition between rounds?
minetruck minetruck

2020/2/9

#
no i just mean when i reset the game
danpost danpost

2020/2/9

#
I think your problem is due to your referencing of both counters in both your world's class and in this actor's class. How are the fields assigned for the actor?
minetruck minetruck

2020/2/9

#
Thats the code of the actor( the laser of the shooter who shoots the asteroids):
public void act() 
    {
        move(10);
        if(isTouching(Asteroid2.class)){
            ((TieWorld)getWorld()).isTouchingAsteroid(); 
            getWorld().addObject(new KleineExplosion(), getX(), getY());
            removeTouching(Asteroid2.class);
            getWorld().removeObject(this);
        }
        else
        if (isAtEdge()){
            getWorld().removeObject(this);
        }
        
     
    }
danpost danpost

2020/2/9

#
I cannot see why your high score counter would show 8 when the actual high value was 5. Actually, I cannot see why it would change at all. If both counters start at zero, then if you add to game counter for it to become one (which is not zero), the condition to change high score will not be met -- ever. Maybe you are changing the value for the high score elsewhere. What does your end round code look like?
minetruck minetruck

2020/2/9

#
do you mean this?
public void gameOver (){
        backgroundMusic.stop();
        stopped();
        gameover.play();
        gameover.setVolume(60);
        int x = tie.getX();
        int y = tie.getY();
        addObject(new KleineExplosion(), x, y);
        removeObject(tie);
        addObject(new GameOverScreen(), 450, 300);
    }
danpost danpost

2020/2/9

#
What is in the stopped method?
minetruck minetruck

2020/2/9

#
public void stopped(){
        backgroundMusic.stop();
    }
danpost danpost

2020/2/9

#
Not that it will fix your problem, but why do you stop the music and then call that method to "stop" the music? Still cannot see any reason for your unwanted behavior. Maybe you should upload the scenario (with source included) so it can be thoroughly reviewed.
minetruck minetruck

2020/2/9

#
danpost wrote...
Not that it will fix your problem, but why do you stop the music and then call that method to "stop" the music?
idk i think i forgot to remove it ... but thank you. i think i ll leave it without high score, it is not so important, but still thank you very much
You need to login to post a reply.