Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Author: Nikolay Yunger
- * Date: 10/25/14
- * Assignment: Bugs
- */
- import info.gridworld.actor.Bug;
- public class ZBug extends Bug{
- private int length;
- private int steps;
- private int turns;
- /**
- * Pre: l != 0
- * Post: Constructs a ZBug with a length of l
- */
- public ZBug(int l)
- {
- length = l;
- steps = 0;
- turns = 0;
- }
- /**
- * Pre: none
- * Post: Bug moves in a Z pattern and stops in the end or if something blocks it
- */
- public void act()
- {
- while(canMove() && steps < length)
- {
- move();
- steps++;
- if(turns == 1 && steps == length)
- {
- turn();
- turn();
- turn();
- steps = 0;
- }
- if(steps == length)
- {
- turn();
- turn();
- turn();
- steps = 0;
- turns++;
- }
- }
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement