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

2013/6/24

Need help with scoreboards

Alby Alby

2013/6/24

#
So, I would like to make a project that has a seal that goes around eating fish. I started the seal by declaring a public variable...
    public int points;
The reason it was public instead of private was that I have another class file that will show a message saying how many points you have. What I was mainly wondering was what would be the code for that? Here's the code for the the scoreboard so far (labeled pointholder)
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;

/**
 * This class shows your points
 */
public class PointHolder extends Actor
{
    public PointHolder()
    {
        
    }
}
danpost danpost

2013/6/24

#
Since the 'int points' field is not in the PointHolder class, the class should basically be a Text class whose displayed text can be modified. The constructor should have an argument for the text to display; and it should call a method to 'update' the displayed text. The method updating the displayed text just creates the image to display and sets the image of the actor to that image. Another method should be added to the class to change the text. It should work just like the constructor: having an argument for the new text to display and calling the same method to update that displayed text.
You need to login to post a reply.