CS111
Buggle Contract

Instances of the Buggle class represent whimsical creatures that inhabit an instance of the BuggleWorld class. Conceptually, every buggle has four abstract state variables:

Constructor Methods

Buggle ()
Returns a new buggle at location (1,1) whose heading is Direction.EAST, whose color is Color.red, and whose brush is down.

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. If n is 0, has no effect. If n is less than 0, goes backward n steps.

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 buggle backward n steps. If the buggle encounters a wall along the way, it will stop and complain. If n is 0, has no effect. If n is less than 0, goes forward n steps.

public void left ()
Turns this buggle left by 90 degrees.

public void right ()
Turns this buggle right by 90 degrees.

public Location getPosition ()
Returns a Location instance that specifies the current position of this buggle in the grid.

public void setPosition (Location loc)
Changes the position of this buggle to be the grid location whose x- and y-coordinates are given by the Location instance loc. Complains if loc is not in the grid.

public Direction getHeading ()
Returns a Direction instance that specifies the heading of this buggle.

public void setHeading (Direction d)
Changes the heading of this buggle to be the Direction instance d.

public Color getColor ()
Returns a Color instance that specifies the color of this buggle.

public void setColor (Color c)
Changes the color of this buggle to be the Color instance c.

public void brushDown ()
Ensures this buggle's brush is down. When the brush is down, the buggle leaves a trail when it moves.

public void brushUp ()
Ensures this buggle's brush is up. When the brush is up, the buggle leaves no trail when it moves.

public boolean isBrushDown ()
Returns true if this buggle's brush is down and false if it's up.

public void setBrushDown (boolean b)
If b is true, ensures this buggle's brush is down. If b is false, ensures this buggle's brush is up.

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 void pickUpBagel ()
Picks up the bagel that is in the buggle's cell. Complains if there is no bagel.

public void dropBagel ()
Drops one bagel in the buggle's cell. Complains if a bagel is already present in that cell.

public Color getCellColor ()
Returns the color of the cell under this buggle.

public void setCellColor (Color c)
Changes the cell under this buggle to have the color c.

public void paintCell (Color c)
Paints the cell under this buggle with Color instance c. This is a synonym for setCellColor(c).

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 boolean isOverInt ()
Returns true if the cell below this buggle contains an integer, and false otherwise.

public int pickUpInt ()
Returns the integer in the cell below this buggle. Complains if there is no integer in the cell.

public void dropString (String s)
Drops the string s into the cell below this buggle. If there is already a string (or integer) in the cell, it is replaced by s.

public boolean isOverString ()
Returns true if the cell below this buggle contains a string, and false otherwise. In this context, an integer in the cell is treated as a string of digits.

public String pickUpString ()
Returns the string in the cell below this buggle. Complains if there is no string in the cell. In this context, an integer in the cell is treated as a string of digits.

public boolean isVisible ()
Returns true if this buggle is visible and false if it's invisible.

public void setVisible (boolean b)
If b is true, makes this buggle visible. If b is false, makes this buggle invisible.

public String toString ()
Returns a string representation of this buggle.