New to GridWorld - CircleBug

1.4k views Asked by At

I made a new class called CircleBug which is pretty much the same thing as BoxBug except it turns one time except 2, thus turning the bug in a "circle" instead of a box

Here is BoxBug as found on the collegeboard gridworld manual:

import info.gridworld.actor.Bug;


public class BoxBug extends Bug
 {
private int steps;
private int sideLength;

/**
 * Constructs a box bug that traces a square of a given side length
 * @param length the side length
 */
public BoxBug(int length)
{
    steps = 0;
    sideLength = length;
}

/**
 * Moves to the next location of the square.
 */
@Override
public void act()
{
    if (steps < sideLength && canMove())
    {
        move();
        steps++;
    }
    else
    {
        turn();
        turn();
        steps = 0;
    }
    }
   }

BoxBugRunner:

import info.gridworld.actor.ActorWorld;
 import info.gridworld.grid.Location;

 import java.awt.Color;

 public class BoxBugRunner
{
public static void main(String[] args)
{
    ActorWorld world = new ActorWorld();
    BoxBug alice = new BoxBug(6);
    alice.setColor(Color.ORANGE);
    BoxBug bob = new BoxBug(3);
    world.add(new Location(7, 8), alice);
    world.add(new Location(5, 5), bob);
    world.show();
}
 }

This is my code for Circle Bug and CircleBugRunner:

 package circlebug;

 import info.gridworld.actor.Bug;

 public class CircleBug extends Bug {

private int steps;
private int sideLength;


public CircleBug(int length) {
    steps = 0;
    sideLength = length;
}

@Override
public void act() {
    if (steps < sideLength && canMove()) {
        move();
        steps++;
    } else {
        turn();
        steps = 0;
    }
}
 }

Circle Bug runner:

 package circlebug;

  import info.gridworld.actor.ActorWorld;
 import info.gridworld.grid.Location;
  import java.awt.Color;

 public class CircleBugRunner {

public static void main(String[] args) {
    ActorWorld world2 = new ActorWorld();
    CircleBug alice2 = new CircleBug(6);
    alice2.setColor(Color.RED);
    CircleBug bob2 = new CircleBug(3);
    bob2.setColor(Color.BLUE);
    world2.add(new Location(6, 6), alice2);
    world2.add(new Location(3, 3), bob2);
    world2.show();
}
}

Here's my problem. When I run CircleBug, it only runs BoxBug. Anyone see what is going on? I'm using Netbeans btw.

1

There are 1 answers

0
Freedom On BEST ANSWER

Nevermind, I solved the question - I put BoxBug as the source package so it ran that one.