Results 1 to 3 of 3
  1. #1
    DanK is offline Member
    Join Date
    Dec 2008
    Posts
    10
    Rep Power
    0

    Question Help with java project. Im so close!

    So my project is to:
    Write a class ZBug to implement bugs that move in a “Z” pattern, starting in thetop left corner. After completing one “Z” pattern, a ZBug should stop moving.In any step, if a ZBug can’t move and is still attempting to complete its “Z”pattern, the ZBug does not move and should not turn to start a new side. Supply the length of the “Z” as a parameter in the constructor. The following image shows a “Z” pattern of length 4. Hint: Notice that a ZBug needs to be facingeast before beginning its “Z” pattern.

    I am really close to being done but for some reason my zbug doesnt complete the end of the z. Also im not sure if it will stop once it is done? Can anyone help? Here is my code for ZBug.java:

    import info.gridworld.actor.Bug;

    public class ZBug extends Bug
    {
    private int steps;
    private int sideLength;
    private int moveCount;

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

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

    }
    if (steps==sideLength && getDirection()==90)
    {
    setDirection(225);
    steps = 0;
    //sideLength++;
    }
    else if (steps==sideLength && getDirection()==225)

    setDirection(90);



    }


    And here is my code for ZBugRunner.java:

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

    import java.awt.Color;

    /**
    * This class runs a world that contains box bugs. <br />
    * This class is not tested on the AP CS A and AB exams.
    */
    public class ZBugRunner extends BugRunner
    {
    public static void main(String[] args)
    {
    ActorWorld world = new ActorWorld();
    //ZBug alice = new ZBug(6);
    //alice.setColor(Color.ORANGE);
    ZBug bob = new ZBug(3);
    //world.add(new Location(7, 8), alice);
    world.add(new Location(5, 5), bob);
    world.show();
    }
    }

  2. #2
    DanK is offline Member
    Join Date
    Dec 2008
    Posts
    10
    Rep Power
    0

    Default

    Anyone have an idea?

  3. #3
    champinder is offline Member
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

    Default

    import info.gridworld.actor.Bug;

    /**
    * A <code>BoxBug</code> traces out a square "box" of a given size. <br />
    * The implementation of this class is testable on the AP CS A and AB exams.
    */

    public class Zbug extends Bug {

    private int steps;
    private int sideLength;
    private int count;

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



    /**
    * Moves to the next location of the square.
    */
    public void act() {

    if (steps < sideLength && canMove())
    {
    move();
    steps++;
    }

    else if(count == 0)
    {
    turn();
    turn();
    turn();
    steps = 0;
    count++;
    }

    else if(count == 1)
    {
    turn();
    turn();
    turn();
    turn();
    turn();
    steps = 0;
    count++;
    }
    else if(count == 2)
    {
    turn();
    turn();
    turn();
    turn();
    turn();
    steps=100000000;
    }
    }
    }



    ////////////////////runner................


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


    public class ZBugRunner extends BugRunner {
    public static void main(String[] args)
    {
    UnboundedGrid grid = new UnboundedGrid<Actor>();
    ActorWorld world = new ActorWorld(grid);
    Zbug sp = new Zbug(4);
    sp.setDirection(90);
    world.add(new Location(10,10),sp);


    world.show();
    }
    }

Similar Threads

  1. Close but help would be grateful
    By reader34 in forum New To Java
    Replies: 8
    Last Post: 12-21-2008, 06:42 PM
  2. [SOLVED] Close Exe
    By smartsubroto in forum New To Java
    Replies: 11
    Last Post: 10-14-2008, 09:04 AM
  3. close a frame..
    By tajinvillage in forum New To Java
    Replies: 5
    Last Post: 04-27-2008, 11:22 PM
  4. How to close a JFrame
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 06:33 PM
  5. Close a program in java
    By romina in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 08:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •