To stop the game you should use Greenfoot.stop(). It's like pressing the run button again. To Count how many crabs are in the game you can use the getObjects method of the world. You can add this method to the world:
public void stopWhenCrabsAreEaten(){
if(getObjects(Crab.class).size()==0)
Greenfoot.stop();
}
Then you have only to add the act method into the world, if you hadn't done this already.
public void act(){
stopWhenCrabsAreEaten();
}
I hope I was able to help you :)
2013/8/16
2013/8/16
2013/9/15