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

2013/11/11

Help with Score

payner2013 payner2013

2013/11/11

#
can anybody help me... i have made a score like this...
public ScoreLabel (String text)
    {
        GreenfootImage img = new GreenfootImage(text.length()*10, 30);
        img.setColor(java.awt.Color.white);
        img.drawString (text, 2, 15);
        setImage(img);
but can someone help me make it work and count up 10 every time my bullet hits and blows up a rock? help will be great, thank you
danpost danpost

2013/11/11

#
Please show the entire 'ScoreLabel' class code. The amount of code given is not very helpful.
payner2013 payner2013

2013/11/11

#
this is all i have in it currently i dont know what to really do with it...
/**
 * Write a description of class ScoreLabel here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ScoreLabel extends Actor
{
    public ScoreLabel (String text)
    {
        GreenfootImage img = new GreenfootImage(text.length()*10, 30);
        img.setColor(java.awt.Color.white);
        img.drawString (text, 2, 15);
        setImage(img);
    }
   public void setText(String text)
   {
    GreenfootImage img = getImage();
    img.clear();
    img.drawString (text, 2, 15);
    }
}
danpost danpost

2013/11/11

#
OK, you will need to obtain or retain a reference to the ScoreLabel object created by this class in the class where the 'score' is located and accumulates in. Then, anytime the score changes, set the text of the ScoreLabel object to the new text showing the new score.
payner2013 payner2013

2013/11/11

#
ok... that is confusing. so am i keeping what i have currently..? :s and how do i make it accumulate... what actor the bullet or the rock... sorry for being like this not really done alot of java brfore thank you
danpost danpost

2013/11/11

#
Whichever class (bullet or rock) that performs the collision detection. The ScoreLabel class does not need modified.
payner2013 payner2013

2013/11/11

#
ok so the rock detects the collision so what would i put in the rocks source code?
danpost danpost

2013/11/11

#
Before we can adjust the ScoreLabel image to display the new score, we need an 'int' field that keeps track of the score. Do you have one yet? and, if so, which class is it in (name the class and what class it extends, back to 'World' or 'Actor') and how is the field declared?
payner2013 payner2013

2013/11/11

#
no i dont, and what do you mean how is the field declared? sorry i bet you hate dealing with newbees
danpost danpost

2013/11/11

#
Please refer to the Java tutorials -- especially the trail on Learning the Java Language.
payner2013 payner2013

2013/11/11

#
ok thank you...
You need to login to post a reply.