aznishboy

spiralBug

Jan 12th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.68 KB | None | 0 0
  1. import info.gridworld.actor.*;
  2. import info.gridworld.grid.*;
  3.  
  4. public class spiralBug extends Bug{
  5.     private int steps;
  6.     private int sideLength;
  7.  
  8.     /**
  9.      * Constructs a box bug that traces a square of a given side length
  10.      * @param length the side length
  11.      */
  12.     public spiralBug(int length)
  13.     {
  14.         steps = 0;
  15.         sideLength = length;
  16.     }
  17.  
  18.     /**
  19.      * Moves to the next location of the square.
  20.      */
  21.     public void act()
  22.     {
  23.         if (steps < sideLength && canMove())
  24.         {
  25.             move();
  26.             steps++;
  27.         }
  28.         else
  29.         {
  30.             turn();
  31.             turn();
  32.             length+=2;
  33.             steps = 0;
  34.         }
  35.     }  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment