Advertisement
yangjason69

FiveFive

Mar 11th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1.  
  2. import kareltherobot.*;
  3. import java.awt.Color;
  4.  
  5. /**
  6.  * Karel turns off if he is surrounded and cannot move.
  7.  *
  8.  * @author  Jason Yang
  9.  *
  10.  * @version 3/11/2017
  11.  */
  12. public class turnOffIfSurrounded extends Robot
  13. {
  14.     /**
  15.      * Creates a turnOffIfSurrounded object.
  16.      *
  17.      * @param street     specifies the vertical position on the grid
  18.      *                   of this robot.
  19.      * @param avenue     specifies the horizontal position on the grid
  20.      *                   of this robot.
  21.      * @param direction  specifies the direction of this robot.
  22.      * @param beepers    specifies this robot's number of beepers.
  23.      */
  24.     public turnOffIfSurrounded (int street, int avenue,
  25.            Direction direction, int beepers)
  26.     {
  27.         super(street, avenue, direction, beepers);
  28.     }
  29.     /* turnOffIfSurrounded methods: */
  30.     public void turnOffIfSurrounded(){
  31.         if (frontIsClear()){
  32.             return;          
  33.         }
  34.         turnLeft();
  35.         if (frontIsClear()){
  36.             turnLeft();        
  37.             turnLeft();
  38.             turnLeft();
  39.             return;
  40.         }
  41.         turnLeft();
  42.         if (frontIsClear()){
  43.             turnLeft();
  44.             turnLeft();
  45.             return;
  46.         }
  47.         turnLeft();
  48.         if (frontIsClear()){
  49.             turnLeft();
  50.             return;
  51.         }
  52.         turnOff();
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement