Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.61 KB | None | 0 0
  1.  @Override
  2.     public void move(){
  3.         //aim coordinates
  4.         Point2D.Double aim = new Point2D.Double();
  5.  
  6.         switch(currentDirection){
  7.             case NORTH://if the left handside is a space...
  8.                 if(maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y-1 )==' '
  9.                         ||maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y-1 )=='X'){
  10.                         //...move right
  11.                         aim.x=maze.getRoboCoordinate().x;
  12.                         aim.y=maze.getRoboCoordinate().y-1;
  13.                         maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
  14.                         maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
  15.                         this.setDirection(EAST);
  16.                         break;
  17.                 }else{
  18.                 //if straight is a space...
  19.                 if(maze.getCell((int)maze.getRoboCoordinate().x-1,(int)maze.getRoboCoordinate().y )==' '
  20.                         ||maze.getCell((int)maze.getRoboCoordinate().x-1,(int)maze.getRoboCoordinate().y )=='X'){
  21.                         //...move straight
  22.                         aim.x=maze.getRoboCoordinate().x-1;
  23.                         aim.y=maze.getRoboCoordinate().y;
  24.                         maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
  25.                         maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
  26.                         this.setDirection(this.getDirection());
  27.                         break;
  28.                 }else{
  29.                 //if right handside is a space...
  30.                 if(maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y+1 )==' '
  31.                         ||maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y+1 )=='X'){
  32.                         //...move left
  33.                         aim.x=maze.getRoboCoordinate().x;
  34.                         aim.y=maze.getRoboCoordinate().y+1;
  35.                         maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
  36.                         maze.setCell((int)aim.x,(int)aim.y,'r'); //sert the new r
  37.                         this.setDirection(WEST);
  38.                 break;
  39.                 }else{
  40.                 //turn around...
  41.                     setDirection(SOUTH);
  42.                 break;
  43.                 }
  44.                 }
  45.                 }
  46.             case EAST://if the left handside is a space...
  47.                 if(maze.getCell((int)maze.getRoboCoordinate().x-1,(int)maze.getRoboCoordinate().y )==' '
  48.                         ||maze.getCell((int)maze.getRoboCoordinate().x-1,(int)maze.getRoboCoordinate().y )=='X'){
  49.                         //...move right
  50.                         aim.x=maze.getRoboCoordinate().x-1;
  51.                         aim.y=maze.getRoboCoordinate().y;
  52.                         maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
  53.                         maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
  54.                         this.setDirection(SOUTH);
  55.                         break;
  56.                 }else{
  57.                 //if straight is a space...
  58.                 if(maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y+1 )==' '
  59.                         ||maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y+1 )=='X'){
  60.                         //...move straight
  61.                         aim.x=maze.getRoboCoordinate().x;
  62.                         aim.y=maze.getRoboCoordinate().y+1;
  63.                         maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
  64.                         maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
  65.                         this.setDirection(this.getDirection());
  66.                         break;
  67.                 }else{
  68.                 //if right handside is a space...
  69.                 if(maze.getCell((int)maze.getRoboCoordinate().x+1,(int)maze.getRoboCoordinate().y )==' '
  70.                         ||maze.getCell((int)maze.getRoboCoordinate().x+1,(int)maze.getRoboCoordinate().y )=='X'){
  71.                         //...move left
  72.                         aim.x=maze.getRoboCoordinate().x+1;
  73.                         aim.y=maze.getRoboCoordinate().y;
  74.                         maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
  75.                         maze.setCell((int)aim.x,(int)aim.y,'r'); //sert the new r
  76.                         this.setDirection(NORTH);
  77.                 break;
  78.                 }else{
  79.                 //turn around...
  80.                     setDirection(WEST);
  81.                 break;
  82.                 }
  83.                 }
  84.                 }
  85.             case SOUTH:
  86.                 //if the left handside is a space...
  87.                 if(maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y+1 )==' '
  88.                         ||maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y+1 )=='X'){
  89.                         //...move right
  90.                         aim.x=maze.getRoboCoordinate().x;
  91.                         aim.y=maze.getRoboCoordinate().y+1;
  92.                         maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
  93.                         maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
  94.                         this.setDirection(WEST);
  95.                         break;
  96.                 }else{
  97.                 //if straight is a space...
  98.                 if(maze.getCell((int)maze.getRoboCoordinate().x+1,(int)maze.getRoboCoordinate().y )==' '
  99.                         ||maze.getCell((int)maze.getRoboCoordinate().x+1,(int)maze.getRoboCoordinate().y )=='X'){
  100.                         //...move straight
  101.                         aim.x=maze.getRoboCoordinate().x+1;
  102.                         aim.y=maze.getRoboCoordinate().y;
  103.                         maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
  104.                         maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
  105.                         this.setDirection(this.getDirection());
  106.                         break;
  107.                 }else{
  108.                 //if right handside is a space...
  109.                 if(maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y-1 )==' '
  110.                         ||maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y-1 )=='X'){
  111.                         //...move left
  112.                         aim.x=maze.getRoboCoordinate().x;
  113.                         aim.y=maze.getRoboCoordinate().y-1;
  114.                         maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
  115.                         maze.setCell((int)aim.x,(int)aim.y,'r'); //sert the new r
  116.                         this.setDirection(EAST);
  117.                 break;
  118.                 }else{
  119.                 //turn around...
  120.                     setDirection(NORTH);
  121.                 break;
  122.                 }
  123.                 }
  124.                 }
  125.             case WEST://if the left handside is a space...
  126.                 if(maze.getCell((int)maze.getRoboCoordinate().x+1,(int)maze.getRoboCoordinate().y )==' '
  127.                         ||maze.getCell((int)maze.getRoboCoordinate().x+1,(int)maze.getRoboCoordinate().y )=='X'){
  128.                         //...move right
  129.                         aim.x=maze.getRoboCoordinate().x+1;
  130.                         aim.y=maze.getRoboCoordinate().y;
  131.                         maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
  132.                         maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
  133.                         this.setDirection(NORTH);
  134.                         break;
  135.                 }else{
  136.                 //if straight is a space...
  137.                 if(maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y-1 )==' '
  138.                         ||maze.getCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y-1 )=='X'){
  139.                         //...move straight
  140.                         aim.x=maze.getRoboCoordinate().x;
  141.                         aim.y=maze.getRoboCoordinate().y-1;
  142.                         maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
  143.                         maze.setCell((int)aim.x,(int)aim.y,'r'); //set the new r
  144.                         this.setDirection(this.getDirection());
  145.                         break;
  146.                 }else{
  147.                 //if right handside is a space...
  148.                 if(maze.getCell((int)maze.getRoboCoordinate().x-1,(int)maze.getRoboCoordinate().y )==' '
  149.                         ||maze.getCell((int)maze.getRoboCoordinate().x-1,(int)maze.getRoboCoordinate().y )=='X'){
  150.                         //...move left
  151.                         aim.x=maze.getRoboCoordinate().x-1;
  152.                         aim.y=maze.getRoboCoordinate().y;
  153.                         maze.setCell((int)maze.getRoboCoordinate().x,(int)maze.getRoboCoordinate().y,' '); //erase the old r
  154.                         maze.setCell((int)aim.x,(int)aim.y,'r'); //sert the new r
  155.                         this.setDirection(SOUTH);
  156.                 break;
  157.                 }else{
  158.                 //turn around...
  159.                     setDirection(EAST);
  160.                 break;
  161.                 }
  162.                 }
  163.                 }
  164.         }
  165.  
  166.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement