Advertisement
GARC923

EsperBot

Oct 21st, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1. /**
  2. EsperBot File for lesson 4
  3. */
  4.  
  5. package Lesson4;
  6.  
  7. import kareltherobot.Robot;
  8. import kareltherobot.World;
  9.  
  10. import java.sql.Wrapper;
  11. import java.util.Scanner;
  12.  
  13.  
  14. public class EsperBot extends Robot {
  15.     public EsperBot(int street, int avenue, Direction direction, int beeperCount) {
  16.         super(street, avenue, direction, beeperCount);
  17.     }
  18.  
  19.  
  20.     public static void main(String[] args) {
  21.         World.setDelay(50);
  22.         World.setVisible();
  23.         World.setSize(10, 10);
  24.         World.showSpeedControl(true);
  25.  
  26.         Lesson3.Activity1 zgod = new Lesson3.Activity1(1, 3, North, -1);
  27.  
  28.         zgod.shuttleRun();
  29.     }
  30.     /**
  31.      * Turns right
  32.      * @return void
  33.      * */
  34.     public void turnRight(){
  35.         World.setDelay(0);
  36.         turnLeft();
  37.         turnLeft();
  38.         World.setDelay(50);
  39.         turnLeft();
  40.     }
  41.  
  42.     /**
  43.      * Determines whether the left is clear
  44.      * @return boolean
  45.      * */
  46.     boolean retLeft = true;
  47.     public boolean leftIsClear() {
  48.         if (facingNorth()) { //positions the robot to face west
  49.             turnLeft();
  50.         }
  51.         else if (facingSouth()) { //positions the robot to face west
  52.             turnRight();
  53.         }
  54.         else if (facingEast()) { //positions the robot to face west
  55.             turnLeft();
  56.             turnLeft();
  57.         }
  58.         if (frontIsClear()){ // checks if the front is clear. If it is, it returns true
  59.             retLeft = true;
  60.         }else {
  61.             retLeft = false;
  62.         }
  63.         turnRight();
  64.         return retLeft;
  65.     }
  66.  
  67.     /**
  68.      * Method to detect whether there is a stair in front of the robot to go up
  69.      * @return boolean
  70.      * */
  71.     boolean retStair = true;
  72.     public boolean inStair(){
  73.         if (facingNorth()){
  74.             turnRight();
  75.         }
  76.         if (frontIsClear()) {
  77.             retStair = false;
  78.         }
  79.         else{
  80.             retStair = true;
  81.         }
  82.         turnLeft();
  83.         return retStair;
  84.     }
  85. }
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement