Here are a few codes I have typed up in a failed attempt to Design the default DogWorld to contain three Dog objects at random locations and one player-controllable Dog object precisely at the center of the DogWorld. The IDE is Greenfoot.
public class DogWorld extends World
{
/**
* Constructor for objects of class DogWorld.
*
*/
public DogWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
randomDogs();
}
/**
* This method add a random dog
*/
public void randomDogs()
if ( Greenfoot.getRandomNumber(10) )
{
addObject ( new Dog() 100, 67 );
}
}
public class Dog extends Actor
{
private int lastObject = 0;
public void act()
{
if (int lastObject i = Greenfoot.getRandomNumber;(4)+ 1;
{
while (i== lastObjectNumber) i = Greenfoot.getRandomNumber(4) + 1;
lastObject = i;
if (i==1)
{
}
I also tried to extrapolate from:
http://www.greenfoot.org/topics/713
It is not exactly the same thing, but the Greenfoot textbook is not clear on how to apply the instance variable.

