Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Moves alphaBot until it reaches the tower, then it climbs
- * By: Alejandro Antorcha
- */
- package Lesson4;
- import kareltherobot.*;
- public class Activity2Lesson4 extends Robot{
- public Activity2Lesson4(int x, int y, Direction d, int b) {
- super(x, y, d, b);
- }
- public static void main(String[] args) {
- World.readWorld("Lesson4World2.kwld");
- World.setDelay(15);
- World.setVisible();
- Robot alphaBot = new Activity2Lesson4(1, 1, East, 0);
- //Runs a loop that calls move() until the robot is facing north and
- // not on a beeper.
- while(!alphaBot.facingNorth() || alphaBot.nextToABeeper()) {
- alphaBot.move();
- }
- }
- /**
- * @Override
- * Moves normally but if it is at the tower, it turns left
- * @param
- * @return void
- */
- public void move() {
- //turns left if at the tower
- if(this.facingEast() && this.nextToABeeper()) {
- this.turnLeft();
- }
- //normal move forward
- super.move();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement