Gubble
class represent
whimsical creatures that are relatives of buggles and
that inhabit an instance of the GubbleWorld
class.
Conceptually, every gubble has four abstract state variables:
Constructor Methods
public Gubble (GubbleWorld gw, Point pos, Direction dir, Color col);
Creates and returns a new gubble with colorcol
that lives in gubbleworldgw
and is initially at positionpos
facing directiondir
.
Instance Methods
public Point getPosition ();
Returns the current position of this gubble in the gubbleworld grid.
public Direction getDirection ();
Returns the direction in which this gubble is facing.
public Color getColor ();
Returns the color of this gubble.
public void left ();
Turns this gubble left by 90 degrees.
public void right ();
Turns this gubble right by 90 degrees.
public void forward ();
Moves this gubble forward one step (in its current direction). Complains if the gubble is facing a wall.
public boolean isBlockedFront ();
Returnstrue
if there is an obstruction (a wall or another gubble) immediately in front of this gubble; otherwise returnsfalse
.
public boolean isInLeftCorner ();
Returnstrue
if there is an obstruction (a wall or another gubble) immediately in front of and to the left of this gubble, but there is no obstruction immediately to the right; otherwise returnsfalse
.
public boolean isInRightCorner ();
Returnstrue
if there is an obstruction (a wall or another gubble) immediately in front of and to the right of this gubble, but there is no obstruction immediately to the left; otherwise returnsfalse
.
public boolean isSurrounded ();
Returnstrue
if there is an obstruction (a wall or another gubble) immediately in front of, to the right of, and to the left of this gubble; otherwise returnsfalse
.
public Gubble copy ();
Returns a new gubble that has the same state (color, direction, position, world) as this buggle. Changes to the resulting gubble should have no effect on the original gubble and vice versa.
public void draw (Graphics g, Rectangle r);
Draws a pictorial representation of this gubble in the given rectangle using the given graphics context. The representation must show the current direction and color of the gubble. Here is a picture of a red gubble facing north:In a square, the head of a gubble is a filled circle that is 25% of its body length, and its abdomen is a filled circle that is 75% of its body length. It also has four legs that project outward from the center of its abdomen. ![]()
public String toString ();
Returns a string representation of this gubble.