the counter in the crab class is a countdown clock which is a different thing and is working well.
here is my crab class:
i appreciate all your help!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Crab here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Crab extends Animals
{
/**
* Act - do whatever the Crab wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private Counter counter;
public Crab(Counter pointCounter)
{
counter = pointCounter;
}
public void act()
{
moveAndTurn();
eatWorm();
}
private void moveAndTurn()
{
if (Greenfoot.isKeyDown ("space"))
move (4);
if (Greenfoot.isKeyDown ("right"))
turn (3);
if (Greenfoot.isKeyDown ("left"))
turn (-3);
}
private void eatWorm()
{
Actor Worm;
Worm = getOneObjectAtOffset (0,0,Worm.class);
if(Worm != null)
{
int x = Greenfoot.getRandomNumber(getWorld().getWidth());
int y = Greenfoot.getRandomNumber(getWorld().getHeight());
Worm.setLocation(x, y);
counter.add(1);
Greenfoot.playSound ("eating.wav");
}
Actor RedWorm;
RedWorm = getOneObjectAtOffset (0,0,RedWorm.class);
if (RedWorm != null)
{
World world;
world = getWorld ();
world.removeObject (RedWorm);
counter.add(5);
Greenfoot.playSound ("eating.wav");
}
if (counter.getValue () == 50)
{
Greenfoot.stop();
Greenfoot.playSound ("fanfare.wav");
getWorld().addObject(new GameWon(), getWorld().getWidth()/2, getWorld().getHeight()/2);
}
}
}