Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import info.gridworld.actor.Bug;
- import java.awt.Color;
- /**
- * A subclass of Bug that makes it turn randomly when it hits a wall.
- * @author Angela Qiu
- * @version 8/30/11
- *
- * @author Period - 3
- * @author Assignment - Random Bugs - UTurnBug
- *
- * @author Sources - n/a
- */
- public class RandomBug extends Bug
- {
- public RandomBug()
- {
- setColor( Color.CYAN );
- }
- public RandomBug( Color bugColor )
- {
- setColor( bugColor );
- }
- public void turn(int angle)
- {
- setDirection(angle);
- }
- // Overrides Bug's act method
- public void act()
- {
- if ( canMove() )
- {
- move();
- int angle = 45 * (int)(Math.random() * 8);
- turn(angle);
- }
- }
- }
Add Comment
Please, Sign In to add comment