![]() |
CS111 Buggle Contract |
Buggle
class represent
whimsical creatures that inhabit an instance of
the BuggleWorld
class. Conceptually, every
buggle has five abstract state variables:
Constructor Methods
Buggle ()
Returns a new buggle
at position (1,1) whose heading is
Direction.EAST
, whose color is Color.red
,
whose brush is down, and whose world is the "current" BuggleWorld.
Instance Methods
public void forward ()
Moves this buggle forward one step (in the direction of its current heading). Complains if the buggle is facing a wall.
public void forward (int n)
Moves this buggle forward n steps. If the buggle encounters a wall along the way, it will stop and complain.
public void backward ()
Moves this buggle backward one step (in the direction opposite to its current heading). Complains if the buggle is facing a wall.
public void backward (int n)
Moves this backward n steps. If the buggle encounters a wall along the way, it will stop and complain.
public void left ()
Turns this buggle left by 90 degrees.
public void right ()
Turns this buggle right by 90 degrees.
public void brushDown ()
Lowers this buggle's brush. When the brush is lowered, the buggle leaves a trail when it moves.
public void brushUp ()
Raises this buggle's brush. When the brush is raised, the buggle leaves no trail when it moves.
public boolean isFacingWall ()
Returns true
if there is a wall in front of the buggle, and false
otherwise.
public boolean isOverBagel ()
Returns true
if the buggle is in a cell that contains a bagel, and false
otherwise.
public Color getCellColor ()
Returns the color of the cell under this buggle.
public void paintCell (Color c)
Paints the cell under this buggle with color c
.
public void dropBagel ()
Drops a bagel in the cell currently occupied by this buggle.
Complains if there is already a bagel in the cell.
public void pickUpBagel ()
Picks up the bagel in the cell currently occupied by this buggle.
Complains if there is no bagel in the cell.
public void dropInt (int n)
Drops the integer n
into the cell below this buggle.
If there is already an integer in the cell, it is
replaced by n
.
public void dropString (String s)
Drops the string s
into the cell below this buggle.
If there is already a string in the cell, it is replaced
by s
.
public Point getPosition ()
Returns a point that indicates the current position of this buggle in
the grid. Modifying the returned point will not affect the
buggle's position.
public void setPosition (Point p)
Changes the position of this buggle to be the grid location whose x-
and y-coordinates are given by the point p
.
Complains if p
is not in the grid. Subsequent
modifications of p
will not affect the buggle's
position.
public Direction getHeading ()
Returns the heading of this buggle.
public void setHeading (Direction d)
Changes the heading of this buggle to be the direction d.
public Color getColor ()
Returns the color of this buggle.
public void setColor (Color c)
Changes the color of this buggle to be the color c
.
public String toString ()
Returns a string representation of this buggle.