Monday, March 30, 2009

Lobster Java Coding

Hello all,

The following Java code is an example of the code used to animate the Lobster in the "Crab World" game.
Use this code to experiment with the lobster.

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()
{
if (atWorldEdge()) {
turn(17);
}
move();
if (Greenfoot.getRandomNumber(100) > 90) {
turn(Greenfoot.getRandomNumber(90)-45);
}
if (canSee(Crab.class)) {
eat(Crab.class);
}
}
}


Have fun learning.
John.

No comments: