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

2011/12/30

Need help on making a scoreboard

programmer22 programmer22

2011/12/30

#
I want a scoreboard at the end of my game when you lose or die. Want it to be along the lines of GAME OVER Score:(***) TRY AGAIN? ive had a score board before but never was able to get it to apear at the end of the game anyhelp?
danpost danpost

2011/12/30

#
I have created scoreboard objects for several of my scenarios. Most of the time, I will create and add the scoreboard to the world at scenario start-up, giving the world a reference to the scoreboard object. The image of the scoreboard can be small or transparent until game-over, at which time the image changes to what you want at that time. The scoreboard object can store the score, initially set to zero, and have a public method to adjust the score throughout the game. The act method can either be empty, or just check for game over, at which time it changes the image and stops the scenario. One of the scoreboard classes looks like this
import greenfoot.*;
import java.awt.Color;

public class ScoreBoard extends Actor
{
    private int score = 0;
    private int tenCount = 0;

    public ScoreBoard()
    {
        bumpScore(0);
    }
    
    public void act()
    {
        if (tenCount != 50) return;
        setLocation(getX(), 300);
        GreenfootImage sb = new GreenfootImage("Score: " + score, 60, Color.GREEN, null);
        sb.setTransparency(224);
        setImage(sb);
        Greenfoot.stop();
    }
    
    public void bumpScore(int scored)
    {
        score += scored;
        GreenfootImage sb = new GreenfootImage("Score: " + score, 24, Color.BLACK, null);
        setImage(sb);
        if (scored == 10) tenCount++;
    }
}
With this code, every time a score of ten is registered in bumpScore(int), it increments tenCount. In act(), tenCount is checked to see if fifty tenCounts have been registered, which determines GameOver. So, if not, the return exits act(), otherwise we change the image of the scoreboard and stop the scenario. BTW, bumpScore(int) is called in the constructor because the score is showing throughout this game. Hope this helps!
thetibster thetibster

2011/12/31

#
also, if you have the greenfoot book scenarios downloaded, you can reference the scenario asteroids-3 in chapter 7. It has a scoreboard that pops up at the end, I believe exactly the way you're trying to. I don't believe it is programmed to count the score yet, but you can add that yourself if you already know how to do scoreboards. hope this was helpful:)
You need to login to post a reply.