This is a bonus program! It's meant to be a bit challenging, but completing this program will definitely help you write your final project.

Write a GraphicsProgram that moves a box counter-clockwise around the border of the canvas.

BorderKarel

BonusMethods: BorderKarel.java

Before we start with the Java version, let's write the Karel version. Implement the Karel version in BorderKarel.java. Remember that Karel always starts out in the bottom-left; move him counter-clockwise around the border of the map. Make him move forever!

BorderBox

BonusMethods: BorderBox.java

Now open BorderBox.java. Copy over your border-moving code from BorderKarel. Remember to rename move() to moveBox(), as you will need to define moveBox().

Instead of Karel, we now have a box (a GRect), represented by the following two variables:

private GRect box;
private int boxDirection = EAST; // starting direction

Box Setup

Make the box by implementing the method makeBox(). Like Karel, start him off in the bottom-left of the canvas.

Move eastward

For the time being, let's get our box moving a bit! Set frontIsClear() to always return true for now (it currently always returns false) so that we can just test our box moving in one direction.

Implement moveBox() similar to the Karel functionality; that is, move one step in the direction that the box is facing. Our lovely box starts out facing east, so implement moveBox to move just one step to the right. Make sure it moves SQUARE_LENGTH + SQUARE_GAP!

Now implement frontIsClear() so that our box stops when it reaches the rightmost wall.

Move along the border

You're almost there! In order to move along the border, we need to implement turnLeft(), and also extend our frontIsClear() and moveBox() to handle different directions.

Start by implementing turnLeft(). Hint: you should only be changing the boxDirection; you shouldn't see anything happen visually to the box, since it's a square and exhibits rotational symmetry.

Finally, implement moveBox() and frontIsClear(), depending on which direction the box is facing. Again, remember to move the box SQUARE_LENGTH + SQUARE_GAP!