We'll need two Classes: the CircleBug class and the CircleBugRunner Class.
import java.awt.Color;
import info.gridworld.actor.Bug;
public class CircleBug extends Bug
{
private int steps;
private int sideLength;
public CircleBug(int n)
{
sideLength=n;
steps=0;
}
public void act()
{
if (steps < sideLength && canMove())
{
move();
steps++;
}
else
{
turn();
steps=0;
}
}
}
import info.gridworld.actor.ActorWorld;
import info.gridworld.grid.Location;
import java.awt.Color;
/**
* This class runs a world that contains circle bugs.
* This class is not tested on the AP CS A and AB exams.
*/
public class CircleBugRunner
{
public static void main(String[] args)
{
ActorWorld world = new ActorWorld();
CircleBug a = new CircleBug(2);
a.setColor(Color.BLUE);
world.add(new Location(7, 2), a);
a.setDirection(Location.NORTHEAST);
world.show();
}
}
import info.gridworld.actor.ActorWorld;
import info.gridworld.grid.Location;
import java.awt.Color;
/**
* This class runs a world that contains circle bugs.
* This class is not tested on the AP CS A and AB exams.
*/
public class CircleBugRunner2
{
public static void main(String[] args)
{
ActorWorld world = new ActorWorld();
CircleBug a = new CircleBug(3, Color.RED, Location.NORTH);
world.add(new Location(7,2), a);
world.show();
}
}