also does the counter need to be a world or an actor?
import Greenfoot.*; import java.util.List; // needed to create a list and use its methods
public class Crab extends Actor
{
/**
* Act - do whatever the Crab wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// etc. public void eat()
{
Actor worm;
worm = getOneObjectAtOffset (0, 0, Worm.class);
if (worm != null)
{
World world;
world = getWorld();
world. removeObject(worm);
List<Counter> counters = world.getObjects(Counter.class); // this lists all counters in the world (even if just one)
Counter counter = counters.get(0); // this get the first counter from the list (the only one)
counter.add(5); // this adds 5 to the counter pulled from the list
Greenfoot.playSound("eating.wav");
}
}