Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.52 KB | None | 0 0
  1. package hw2sp14;
  2.  
  3. public class RightHandRobot extends Robot{
  4.  
  5.    
  6.    
  7.     public RightHandRobot(Maze maze){
  8.         super(maze);
  9.         facing = 'S';
  10.     }
  11.    
  12.     public int chooseMoveDirection() {
  13.         int chosenD = 2;
  14.         switch (facing) {
  15.         case 'S':
  16.             chosenD = 2;
  17.         case 'W':
  18.             chosenD = 0;
  19.         case 'E':
  20.             chosenD = 1;
  21.         case 'N':
  22.             chosenD = 3;
  23.         }
  24.         return chosenD;
  25.     }
  26.    
  27.     public boolean move(int direction) {
  28.         boolean moveStatus = false;
  29.         // moveStatus = currentMaze.openCell(currentRow,currentCol);
  30.         // if(moveStatus=true){
  31.         switch (direction) {
  32.         case 0:
  33.             moveStatus = currentMaze.openCell((currentRow - 1), currentCol);
  34.             if (moveStatus == true) {
  35.                 currentMaze.setCell(currentRow, currentCol, ' ');
  36.                 currentRow -= 1;
  37.                 facing = 'N';
  38.                 currentMaze.setCell(currentRow, currentCol, robotName);
  39.             } else {
  40.                 direction = 2;
  41.                 moveStatus = currentMaze.openCell(currentRow, (currentCol - 1));
  42.                 if (moveStatus == true) {
  43.                     currentMaze.setCell(currentRow, currentCol, ' ');
  44.                     currentCol -= 1;
  45.                     facing = 'W';
  46.                     currentMaze.setCell(currentRow, currentCol, robotName);
  47.                 } else {
  48.                     direction = 1;
  49.                     moveStatus = currentMaze.openCell((currentRow + 1),
  50.                             currentCol);
  51.                     if (moveStatus == true) {
  52.                         currentMaze.setCell(currentRow, currentCol, ' ');
  53.                         currentRow += 1;
  54.                         facing = 'S';
  55.                         currentMaze.setCell(currentRow, currentCol, robotName);
  56.                     } else {
  57.                         direction = 3;
  58.                         moveStatus = currentMaze.openCell((currentRow),
  59.                                 (currentCol + 1));
  60.                         if (moveStatus == true) {
  61.                             currentMaze.setCell(currentRow, currentCol, ' ');
  62.                             currentCol += 1;
  63.                             facing = 'E';
  64.                             currentMaze.setCell(currentRow, currentCol,
  65.                                     robotName);
  66.                         }
  67.                     }
  68.  
  69.                 }
  70.             }
  71.             break;
  72.         case 1:
  73.             moveStatus = currentMaze.openCell((currentRow + 1), currentCol);
  74.             if (moveStatus == true) {
  75.                 currentMaze.setCell(currentRow, currentCol, ' ');
  76.                 currentRow += 1;
  77.                 facing = 'S';
  78.                 System.out.println("inside the first if");
  79.                 currentMaze.setCell(currentRow, currentCol, robotName);
  80.             } else {
  81.                 direction = 3;
  82.                
  83.                 moveStatus = currentMaze.openCell((currentRow),
  84.                         (currentCol + 1));
  85.                
  86.                 if (moveStatus == true) {
  87.                     currentMaze.setCell(currentRow, currentCol, ' ');
  88.                     currentCol += 1;
  89.                     facing = 'E';
  90.                     currentMaze.setCell(currentRow, currentCol, robotName);
  91.                 } else {
  92.                     direction = 0;
  93.                     moveStatus = currentMaze.openCell((currentRow - 1),
  94.                             currentCol);
  95.                     if (moveStatus == true) {
  96.                         currentMaze.setCell(currentRow, currentCol, ' ');
  97.                         currentRow -= 1;
  98.                         facing = 'N';
  99.                         currentMaze.setCell(currentRow, currentCol, robotName);
  100.                     } else {
  101.                         direction = 2;
  102.                         moveStatus = currentMaze.openCell(currentRow,
  103.                                 (currentCol - 1));
  104.                         if (moveStatus == true) {
  105.                             currentMaze.setCell(currentRow, currentCol, ' ');
  106.                             currentCol -= 1;
  107.                             facing = 'W';
  108.                             currentMaze.setCell(currentRow, currentCol,
  109.                                     robotName);
  110.                         }
  111.                     }
  112.                 }
  113.             }
  114.             break;
  115.         case 2:
  116.             moveStatus = currentMaze.openCell(currentRow, (currentCol - 1));
  117.             if (moveStatus == true) {
  118.                 currentMaze.setCell(currentRow, currentCol, ' ');
  119.                 currentCol -= 1;
  120.                 facing = 'W';
  121.                 currentMaze.setCell(currentRow, currentCol, robotName);
  122.             } else {
  123.                 direction = 1;
  124.                 moveStatus = currentMaze.openCell((currentRow + 1), currentCol);
  125.                 if (moveStatus == true) {
  126.                     currentMaze.setCell(currentRow, currentCol, ' ');
  127.                     currentRow += 1;
  128.                     facing = 'S';
  129.                     currentMaze.setCell(currentRow, currentCol, robotName);
  130.                 } else {
  131.                     direction = 3;
  132.                     moveStatus = currentMaze.openCell(currentRow,
  133.                             (currentCol + 1));
  134.                     if (moveStatus == true) {
  135.                         currentMaze.setCell(currentRow, currentCol, ' ');
  136.                         currentCol += 1;
  137.                         facing = 'E';
  138.                         currentMaze.setCell(currentRow, currentCol, robotName);
  139.                     } else {
  140.                         direction = 0;
  141.                         moveStatus = currentMaze.openCell((currentRow - 1),
  142.                                 currentCol);
  143.                         if (moveStatus == true) {
  144.                             currentMaze.setCell(currentRow, currentCol, ' ');
  145.                             currentRow -= 1;
  146.                             facing = 'N';
  147.                             currentMaze.setCell(currentRow, currentCol,
  148.                                     robotName);
  149.                         }
  150.                     }
  151.  
  152.                 }
  153.  
  154.             }
  155.             break;
  156.         case 3:
  157.             moveStatus = currentMaze.openCell(currentRow, (currentCol + 1));
  158.             if (moveStatus == true) {
  159.                 currentMaze.setCell(currentRow, currentCol, ' ');
  160.                 currentCol += 1;
  161.                 facing = 'E';
  162.                 currentMaze.setCell(currentRow, currentCol, robotName);
  163.             } else {
  164.                 direction = 0;
  165.                 moveStatus = currentMaze.openCell((currentRow - 1), currentCol);
  166.                 if (moveStatus == true) {
  167.                     currentMaze.setCell(currentRow, currentCol, ' ');
  168.                     currentRow -= 1;
  169.                     facing = 'N';
  170.                     currentMaze.setCell(currentRow, currentCol, robotName);
  171.                 } else {
  172.                     direction = 2;
  173.                     moveStatus = currentMaze.openCell(currentRow,
  174.                             (currentCol - 1));
  175.                     if (moveStatus == true) {
  176.                         currentMaze.setCell(currentRow, currentCol, ' ');
  177.                         currentCol -= 1;
  178.                         facing = 'W';
  179.                         currentMaze.setCell(currentRow, currentCol, robotName);
  180.                     } else {
  181.                         direction = 1;
  182.                         moveStatus = currentMaze.openCell((currentRow + 1),
  183.                                 currentCol);
  184.                         if (moveStatus == true) {
  185.                             currentMaze.setCell(currentRow, currentCol, ' ');
  186.                             currentRow += 1;
  187.                             facing = 'S';
  188.                             currentMaze.setCell(currentRow, currentCol,
  189.                                     robotName);
  190.                         }
  191.                     }
  192.                 }
  193.             }
  194.             break;
  195.         // }
  196.         }
  197.         return moveStatus;
  198.     }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement