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

2013/5/7

Scoring mechanism

Dawn1991 Dawn1991

2013/5/7

#
How do I get a scoring mechanism for the crab scenerio? Like keeping track of how many worms are eaten by the crab and so forth? What is the code?
JetLennit JetLennit

2013/5/7

#
1. Make a static int worms eaten variable called worms (if you don't already have one) 2. Add to that variable every time a worm is eaten 3. Add a class with this code
import greenfoot.*;
import java.awt.Color;

public class WormCounter  extends Actor
{
    public void act()
    {
        updateImage();
    }
    private void updateImage()
    {
        setImage(new GreenfootImage("Worms Eaten:"+ /*change crab to the crab class' name*/ Class.worms, /*this 15 is the size*/15, Color.black, null));
    }
}
You need to login to post a reply.