Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Carlos Garcia
- Challenge 3
- Beeper Trail
- */
- package Challenges;
- import kareltherobot.World;
- public class Challenge3 extends EsperBot3 {
- public Challenge3(int street, int avenue, Direction direction, int beeperCount) {
- super(street, avenue, direction, beeperCount);
- }
- public static void main(String[] args) {
- World.setDelay(5);
- World.setVisible();
- World.setSize(10, 10);
- World.showSpeedControl(true);
- World.readWorld("KarelChallenges3b.kwld");
- Challenge3 zgod = new Challenge3(1, 1, North, -1);
- zgod.followTrail();
- }
- /**
- * Function to follow the trail of beepers
- * @return void
- * */
- public void followTrail(){
- while (!nextToABeeper()) { // only works when Karel is not on a beeper
- if (beeperAhead()) { // picks the beeper ahead if it is ahead
- move();
- pickBeeper();
- } else if (beeperleft()) { // picks the beeper to the left if it is left
- turnLeft();
- move();
- pickBeeper();
- } else if (beeperRight()) { // picks the beeper to the right if it is right
- turnRight();
- move();
- pickBeeper();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement