Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import info.gridworld.actor.Bug;
- import info.gridworld.grid.Location;
- public class CarefulBug 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 CarefulBug(int length)
- {
- steps = 0;
- sideLength = length;
- }
- /**
- * Moves to the next location of the square.
- */
- public void act()
- {
- if (steps < sideLength && canMove())
- {
- move();
- steps++;
- }
- else
- {
- turn();
- turn();
- steps = 0;
- }
- }
- /**
- * Reset Step count
- */
- public void resetCount() {
- steps = 0;
- }
- /**
- * Turns the bug left
- */
- public void turnLeft() {
- setDirection(getDirection() - 45);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement