Guest User

Untitled

a guest
Oct 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import info.gridworld.actor.Bug;
  2. import java.awt.Color;
  3.  
  4. /**
  5. * A subclass of Bug that makes it turn randomly when it hits a wall.
  6.  
  7. * @author Angela Qiu
  8. * @version 8/30/11
  9. *
  10. * @author Period - 3
  11. * @author Assignment - Random Bugs - UTurnBug
  12. *
  13. * @author Sources - n/a
  14. */
  15. public class RandomBug extends Bug
  16. {
  17. public RandomBug()
  18. {
  19. setColor( Color.CYAN );
  20. }
  21.  
  22. public RandomBug( Color bugColor )
  23. {
  24. setColor( bugColor );
  25. }
  26.  
  27. public void turn(int angle)
  28. {
  29. setDirection(angle);
  30. }
  31.  
  32. // Overrides Bug's act method
  33. public void act()
  34. {
  35.  
  36. if ( canMove() )
  37. {
  38. move();
  39. int angle = 45 * (int)(Math.random() * 8);
  40. turn(angle);
  41. }
  42.  
  43. }
  44. }
Add Comment
Please, Sign In to add comment