
Untitled
By: a guest on
Sep 25th, 2012 | syntax:
None | size: 1.74 KB | hits: 16 | expires: Never
/*Susan Tang
*Schull - CS 111
*Username: Stang
*Pset 3
*Task 1
*Due: Sept. 24, 2012
*/
public class Follower extends TickBuggle {
public void tick(){
if(atEnd()){
return;
}
}
//moves Buggle forward and picks up bagel; also picks up any existing bagels under it
public void followBagel(){
brushDown();
if(isOverBagel()){
pickUpBagel();
} else {
forward();
pickUpBagel();
}
}
//looks for a Bagel directly in front of the Buggle
public boolean isBagelPresent(){
if(isFacingWall()){
return false;
} else {
brushUp();
forward();
boolean bagelPresence = isOverBagel();
backward();
brushDown();
return bagelPresence;
}
}
//looks for a Bagel to the left of the Buggle
public boolean leftBagelPresent(){
left();
return isBagelPresent();
}
//lookts for a Bagel to the right of the Buggle
public boolean rightBagelPresent() {
right();
right();
return isBagelPresent();
}
//Searches for the end of the path; if not at the end, the Buggle continues along the Bagel path.
public boolean atEnd() {
boolean endVar = false;
if(isOverBagel()){
pickUpBagel();
} else if (isBagelPresent()) {
followBagel();
} else if (leftBagelPresent()){
followBagel();
} else if (rightBagelPresent()){
followBagel();
} else {endVar = true;
return endVar;}
return endVar;
}
}