Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Challenges;
- import kareltherobot.Robot;
- import kareltherobot.World;
- public class EsperBot3 extends Robot {
- public EsperBot3(int street, int avenue, Direction direction, int beeperCount) {
- super(street, avenue, direction, beeperCount);
- }
- public static void main(String[] args) {
- World.setDelay(50);
- World.setVisible();
- World.setSize(10, 10);
- World.showSpeedControl(true);
- Lesson3.Activity1 zgod = new Lesson3.Activity1(1, 3, North, -1);
- }
- /**
- * Turns right
- * @return void
- */
- public void turnRight() {
- int del = World.delay();
- World.setDelay(0);
- turnLeft();
- turnLeft();
- World.setDelay(del);
- turnLeft();
- }
- /**
- * Turns around
- * @return void
- */
- public void turnAround() {
- int del = World.delay();
- World.setDelay(0);
- turnLeft();
- World.setDelay(del);
- turnLeft();
- }
- /**
- * Checks if the next beeper is ahead
- * @return boolean
- */
- public boolean beeperAhead() {
- boolean beeperAhead = false; // return value: default to false
- if (frontIsClear()) { // only proceeds if the front is clear
- int del = World.delay();
- World.setDelay(0); //delay 0 to make the action instantaneous
- move();
- if (nextToABeeper()) {
- beeperAhead = true; // return is true if when it moves it is on a beeper
- }
- turnAround();
- move();
- World.setDelay(del);
- turnAround(); //goes back to starting position
- }
- return beeperAhead; //return statement
- }
- /**
- * Checks if the next beeper is to the left
- * @return boolean
- */
- public boolean beeperleft(){
- boolean beeperLeft = false; // return value: default to false
- turnLeft();
- if (frontIsClear()) { // only proceeds if the front is clear
- int del = World.delay();
- World.setDelay(0); //delay 0 to make the action instantaneous
- move();
- if (nextToABeeper()) {
- beeperLeft = true; // return is true if when it moves it is on a beeper
- }
- turnAround();
- move();
- World.setDelay(del);
- turnLeft(); //goes back to starting position
- } else turnRight();
- return beeperLeft; //return statement
- }
- /**
- * Checks if the next beeper is right
- * @return boolean
- */
- public boolean beeperRight(){
- boolean beeperRight = false; // return value: default to false
- turnRight();
- if (frontIsClear()) { // only proceeds if the front is clear
- int del = World.delay();
- World.setDelay(0); //delay 0 to make the action instantaneous
- move();
- if (nextToABeeper()) {
- beeperRight = true; // return is true if when it moves it is on a beeper
- }
- turnAround();
- move();
- World.setDelay(del);
- turnRight(); //goes back to starting position
- }else turnLeft();
- return beeperRight; //return statement
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement