Advertisement
Guest User

ZBug Ayy

a guest
Oct 25th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. /**
  2.  * Author: Nikolay Yunger
  3.  * Date: 10/25/14
  4.  * Assignment: Bugs
  5.  */
  6. import info.gridworld.actor.Bug;
  7.  
  8. public class ZBug extends Bug{
  9.     private int length;
  10.     private int steps;
  11.     private int turns;
  12.     /**
  13.      * Pre: l != 0
  14.      * Post: Constructs a ZBug with a length of l
  15.      */
  16.     public ZBug(int l)
  17.     {
  18.         length = l;
  19.         steps = 0;
  20.         turns = 0;
  21.     }
  22.     /**
  23.      * Pre: none
  24.      * Post: Bug moves in a Z pattern and stops in the end or if something blocks it
  25.      */
  26.     public void act()
  27.     {
  28.         while(canMove() && steps < length)
  29.         {
  30.             move();
  31.             steps++;
  32.             if(turns == 1 && steps == length)
  33.             {
  34.                 turn();
  35.                 turn();
  36.                 turn();
  37.                 steps = 0;
  38.             }
  39.             if(steps == length)
  40.             {
  41.                 turn();
  42.                 turn();
  43.                 turn();
  44.                 steps = 0;
  45.                 turns++;
  46.             }
  47.         }
  48.         return;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement