Guest User

Untitled

a guest
Jun 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import info.gridworld.actor.Bug;
  2.  
  3. /**
  4. * A <code>BoxBug</code> traces out a square "box" of a given size. <br />
  5. * The implementation of this class is testable on the AP CS A and AB exams.
  6. */
  7. public class ZBug extends Bug
  8. {
  9. private int steps;
  10. private int sideLength;
  11. public int moo;
  12.  
  13. /**
  14. * Constructs a box bug that traces a square of a given side length
  15. * @param length the side length
  16. */
  17. public ZBug(int length)
  18. {
  19. steps = 0;
  20. moo = 0;
  21. sideLength = length;
  22. turn();
  23. turn();
  24. }
  25.  
  26. /**
  27. * Moves to the next location of the square.
  28. */
  29. public void act()
  30. {
  31. if (moo<3 && steps < sideLength && canMove())
  32. {
  33. move();
  34. steps++;
  35. }
  36. else if(moo == 0)
  37. {
  38. turn();
  39. turn();
  40. turn();
  41. moo++;
  42. steps = 0;
  43. }
  44. else if (moo ==1)
  45. {
  46. setDirection(90);
  47. moo++;
  48. steps = 0;
  49. }
  50. }
  51. }
Add Comment
Please, Sign In to add comment