Advertisement
Guest User

superkarel

a guest
Dec 17th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. import kareltherobot.*;
  2. public abstract class SuperKarel extends Robot implements Directions
  3. {
  4.    public SuperKarel (int street, int avenue, Direction direction, int beepers)
  5.    
  6.    {     super(street, avenue, direction, beepers);
  7.    }
  8.    
  9.    public void turnRight()
  10.    {
  11.       turnLeft();
  12.       turnLeft();
  13.       turnLeft();
  14.    }
  15.  
  16.    public void turnAround()
  17.    {
  18.       turnLeft();
  19.       turnLeft();
  20.    }
  21.  
  22.    public boolean rightIsClear()
  23.    {
  24.       turnRight();
  25.       if (frontIsClear()) {
  26.          turnLeft();
  27.          return true;
  28.       }
  29.    
  30.       turnLeft();
  31.       return false;
  32.    }
  33.  
  34.    public boolean leftIsClear()
  35.    {
  36.       turnLeft();
  37.       if (frontIsClear()) {
  38.          turnRight();
  39.          return true;
  40.       }
  41.    
  42.       turnRight();
  43.       return false;
  44.    }
  45.    
  46.    public void faceNorth()
  47.    {  
  48.       if (facingEast())
  49.       {
  50.          turnLeft();
  51.       }
  52.       if (facingSouth())
  53.       {
  54.          turnLeft();
  55.          turnLeft();
  56.       }
  57.       if (facingWest())
  58.       {
  59.          turnLeft();
  60.          turnLeft();
  61.          turnLeft();
  62.       }
  63.    }
  64.    
  65.    public void faceSouth()
  66.    {  
  67.       if (facingWest())
  68.       {
  69.          turnLeft();
  70.       }
  71.       if (facingNorth())
  72.       {
  73.          turnLeft();
  74.          turnLeft();
  75.       }
  76.       if (facingEast())
  77.       {
  78.          turnLeft();
  79.          turnLeft();
  80.          turnLeft();
  81.       }
  82.    }
  83.    
  84.    public void faceEast()
  85.    {
  86.       if (facingSouth())
  87.       {
  88.          turnLeft();
  89.       }
  90.       if (facingWest())
  91.       {
  92.          turnLeft();
  93.          turnLeft();
  94.       }
  95.       if (facingNorth())
  96.       {
  97.          turnLeft();
  98.          turnLeft();
  99.          turnLeft();
  100.       }
  101.  
  102.    }
  103.    
  104.    public void faceWest()
  105.    {
  106.       if (facingNorth())
  107.       {
  108.          turnLeft();
  109.       }
  110.       if (facingEast())
  111.       {
  112.          turnLeft();
  113.          turnLeft();
  114.       }
  115.       if (facingSouth())
  116.       {
  117.          turnLeft();
  118.          turnLeft();
  119.          turnLeft();
  120.       }
  121.    }
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement