Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Challenges;
- import kareltherobot.Robot;
- import kareltherobot.World;
- public class EsperBot1 extends Robot {
- public EsperBot1(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();
- }
- /**
- * Checks if there is a wall to the left
- * @return boolean
- */
- public boolean leftIsClear(){
- boolean RETleftIsClear = true;
- int del = World.delay();
- World.setDelay(0);
- if (facingNorth()){
- turnLeft();
- if (frontIsClear()) {
- RETleftIsClear = true; // left is clear if front is clear when facing left
- } else{
- RETleftIsClear = false; // left is not clear if front is not clear when facing left
- }
- World.setDelay(del);
- turnRight(); // goes back to starting position
- }
- return RETleftIsClear;
- }
- /**
- * Goes into the cubby
- * @return int
- */
- public int leftEnd(){
- int distance = 0;
- while (frontIsClear()) {
- move(); // moves forwards until it is against the cubby wall
- distance++; // counts how deep the cubby is
- }
- return distance;
- }
- /**
- * Measures the width of the hallway
- * @return int
- */
- public int measureHallway(){
- int hallwayLength = 0;
- turnRight();
- while (frontIsClear()) {
- move();
- hallwayLength++; // counts 1 more distance every time it moves
- }
- turnRight();
- turnRight();
- while (frontIsClear()) {
- move(); //goes back to stating place
- }
- turnRight();
- return hallwayLength;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement