import java.awt.Color; // A skeleton for Abby's alternative implementation of the simplified Buggle class // from Lecture 19. // These buggles have the usual buggle state (position, heading, color, brushDown), // but cannot drop/detect bagels, detect walls, leave a trail, or set cell colors. // This is a skeleton of a class that you need to flesh out for PS10 Task 1. public class AbbyBuggle { // Instance variables: private int[] pos; // position of buggle: a 2-element array of {x,y} private int[] dir; // heading of buggle: a 2-element array of {delta-x,delta-y} private int col; // color of buggle: an integer representation of the color private int brushDown; // brush state of buggle: 0 = false, 1 = true // Constructor method: public AbbyBuggle () { // flesh out this constructor method } // Instance methods: public Location getPosition() { // replace this stub: return new Location(17,23); } public void setPosition (Location loc) { // flesh out this instance method } public Direction getHeading() { // replace this stub: return Direction.SOUTH; } public void setHeading (Direction d) { // flesh out this instance method } public Color getColor() { // replace this stub: return Color.magenta; } public void setColor (Color c) { // flesh out this instance method } public boolean isBrushDown() { // replace this stub: return false; } public void brushDown() { // flesh out this instance method } public void brushUp() { // flesh out this instance method } // To rotate left by 90 degrees, new_x = -y; new_y = x. public void left() { int new_x = -dir[1]; int new_y = dir[0]; dir[0] = new_x; dir[1] = new_y; } // To rotate right by 90 degrees, new_x = y; new_y = -x. public void right() { // flesh out this instance method } public void forward() { // flesh out this instance method } public void forward (int n) { pos[0] += n*dir[0]; // Recall that this means: pos[0] = pos[0] + n*dir[0]; pos[1] += n*dir[1]; } public void backward() { // flesh out this instance method } public void backward (int n) { // flesh out this instance method } public String toString () { return "[AbbyBuggle: pos = " + getPosition() + ";\n dir = " + getHeading() + ";\n col = " + getColor() + ";\n brushDown = " + isBrushDown() + "]"; } // This main method exercises all the methods of AbbyBuggle. public static void main (String[] args) { AbbyBuggle becky = new AbbyBuggle(); System.out.println("Initial state:\n" + becky); for (int i = 1; i <= 3; i++) { Location loc = becky.getPosition(); becky.setPosition(new Location(loc.y + 3, 2*loc.x + 4)); Direction d = becky.getHeading(); becky.setHeading(d.left()); Color c = becky.getColor(); becky.setColor(new Color(c.getBlue(), c.getGreen(), c.getRed()/2)); if (becky.isBrushDown()) becky.brushUp(); else becky.brushDown(); System.out.println("State at beginning of step " + i + ":\n" + becky); becky.forward(2*i); becky.left(); becky.backward(i); becky.left(); becky.forward(i); becky.right(); becky.backward(); System.out.println("State at end of step " + i + ":\n" + becky); } } }