So I´ve the scenario with the crabs, the lobsters and the worms. What I want to do is, everytime the lobster eats a crab he should make a slurp.
What´s wrong here?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class lobster here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class lobster extends Animal
{
/**
* Act - do whatever the lobster wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
turnAtWorldEdge();
lookforcrab();
eat();
}
public void lookforcrab()
{
if(canSee(Crab.class))
{
eat(Crab.class);
}
}
public void eat()
{
Actor Crab;
Crab = getOneObjectAtOffset(0, 0, Crab.class);
if(Crab != null)
{
World world;
world = getWorld();
world.removeObject(Crab);
Greenfoot.playSound("slurp.wav");
}
}
public void randomTurn()
{
if(Greenfoot.getRandomNumber(10) == 0)
{
turn(Greenfoot.getRandomNumber(90)-45);
}
}
public void turnAtWorldEdge()
{
if(atWorldEdge() == true)
{
turn(Greenfoot.getRandomNumber(20));
move();
}
else
{
randomTurn();
}
}
}
