Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import info.gridworld.actor.Actor;
- import info.gridworld.actor.Rock;
- import info.gridworld.grid.Grid;
- import info.gridworld.grid.Location;
- public class RollingRock extends Rock {
- private static final Color DEFAULT_COLOR = Color.BLACK;
- /**
- * Constructs a black rock.
- */
- public RollingRock()
- {
- setColor(DEFAULT_COLOR);
- setDirection(135);
- }
- /**
- * Constructs a rock of a given color.
- * @param rockColor the color of this rock
- */
- public RollingRock(Color rockColor)
- {
- setColor(rockColor);
- setDirection(135);
- }
- /**
- * Rolls the rock
- */
- public void act()
- {
- roll();
- }
- /**
- * Rolls the rock forward
- */
- public void roll()
- {
- Grid<Actor> gr = getGrid();
- if (gr == null)
- return;
- Location loc = getLocation();
- Location next = loc.getAdjacentLocation(getDirection());
- if (gr.isValid(next))
- moveTo(next);
- else
- removeSelfFromGrid();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement