Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- public int moo;
- /**
- * Constructs a box bug that traces a square of a given side length
- * @param length the side length
- */
- public ZBug(int length)
- {
- steps = 0;
- moo = 0;
- sideLength = length;
- turn();
- turn();
- }
- /**
- * Moves to the next location of the square.
- */
- public void act()
- {
- if (moo<3 && steps < sideLength && canMove())
- {
- move();
- steps++;
- }
- else if(moo == 0)
- {
- turn();
- turn();
- turn();
- moo++;
- steps = 0;
- }
- else if (moo ==1)
- {
- setDirection(90);
- moo++;
- steps = 0;
- }
- }
- }
Add Comment
Please, Sign In to add comment