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: Additionally, each buggle must "know" which instance of BuggleWorld it lives in.

Constructor Methods

Buggle ()
Returns a new buggle at position (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.

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 void dropBagel ()
Drops a bagel in the cell currently occupied by this buggle. If there is already a bagel in the cell, tbe buggle complains.

public void pickUpBagel ()
Picks up the bagel in the cell currently occupied by this buggle. If there is no bagel in the cell, the buggle complains.

public Point getPosition ()
Returns a point that indicates the current position of this buggle in the grid.

public void setPosition (Point p)
Changes the position of this buggle to be the point p. Complains if p is not in the grid.

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 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 dropInt (int n)
Drops the integer n into the cell below this buggle.

public void dropString (String s)
Drops the string s into the cell below this buggle.

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