Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hw2sp14;
- public class RightHandRobot extends Robot{
- public RightHandRobot(Maze maze){
- super(maze);
- facing = 'S';
- }
- public int chooseMoveDirection() {
- int chosenD = 2;
- switch (facing) {
- case 'S':
- chosenD = 2;
- case 'W':
- chosenD = 0;
- case 'E':
- chosenD = 1;
- case 'N':
- chosenD = 3;
- }
- return chosenD;
- }
- public boolean move(int direction) {
- boolean moveStatus = false;
- // moveStatus = currentMaze.openCell(currentRow,currentCol);
- // if(moveStatus=true){
- switch (direction) {
- case 0:
- moveStatus = currentMaze.openCell((currentRow - 1), currentCol);
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentRow -= 1;
- facing = 'N';
- currentMaze.setCell(currentRow, currentCol, robotName);
- } else {
- direction = 2;
- moveStatus = currentMaze.openCell(currentRow, (currentCol - 1));
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentCol -= 1;
- facing = 'W';
- currentMaze.setCell(currentRow, currentCol, robotName);
- } else {
- direction = 1;
- moveStatus = currentMaze.openCell((currentRow + 1),
- currentCol);
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentRow += 1;
- facing = 'S';
- currentMaze.setCell(currentRow, currentCol, robotName);
- } else {
- direction = 3;
- moveStatus = currentMaze.openCell((currentRow),
- (currentCol + 1));
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentCol += 1;
- facing = 'E';
- currentMaze.setCell(currentRow, currentCol,
- robotName);
- }
- }
- }
- }
- break;
- case 1:
- moveStatus = currentMaze.openCell((currentRow + 1), currentCol);
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentRow += 1;
- facing = 'S';
- System.out.println("inside the first if");
- currentMaze.setCell(currentRow, currentCol, robotName);
- } else {
- direction = 3;
- moveStatus = currentMaze.openCell((currentRow),
- (currentCol + 1));
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentCol += 1;
- facing = 'E';
- currentMaze.setCell(currentRow, currentCol, robotName);
- } else {
- direction = 0;
- moveStatus = currentMaze.openCell((currentRow - 1),
- currentCol);
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentRow -= 1;
- facing = 'N';
- currentMaze.setCell(currentRow, currentCol, robotName);
- } else {
- direction = 2;
- moveStatus = currentMaze.openCell(currentRow,
- (currentCol - 1));
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentCol -= 1;
- facing = 'W';
- currentMaze.setCell(currentRow, currentCol,
- robotName);
- }
- }
- }
- }
- break;
- case 2:
- moveStatus = currentMaze.openCell(currentRow, (currentCol - 1));
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentCol -= 1;
- facing = 'W';
- currentMaze.setCell(currentRow, currentCol, robotName);
- } else {
- direction = 1;
- moveStatus = currentMaze.openCell((currentRow + 1), currentCol);
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentRow += 1;
- facing = 'S';
- currentMaze.setCell(currentRow, currentCol, robotName);
- } else {
- direction = 3;
- moveStatus = currentMaze.openCell(currentRow,
- (currentCol + 1));
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentCol += 1;
- facing = 'E';
- currentMaze.setCell(currentRow, currentCol, robotName);
- } else {
- direction = 0;
- moveStatus = currentMaze.openCell((currentRow - 1),
- currentCol);
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentRow -= 1;
- facing = 'N';
- currentMaze.setCell(currentRow, currentCol,
- robotName);
- }
- }
- }
- }
- break;
- case 3:
- moveStatus = currentMaze.openCell(currentRow, (currentCol + 1));
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentCol += 1;
- facing = 'E';
- currentMaze.setCell(currentRow, currentCol, robotName);
- } else {
- direction = 0;
- moveStatus = currentMaze.openCell((currentRow - 1), currentCol);
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentRow -= 1;
- facing = 'N';
- currentMaze.setCell(currentRow, currentCol, robotName);
- } else {
- direction = 2;
- moveStatus = currentMaze.openCell(currentRow,
- (currentCol - 1));
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentCol -= 1;
- facing = 'W';
- currentMaze.setCell(currentRow, currentCol, robotName);
- } else {
- direction = 1;
- moveStatus = currentMaze.openCell((currentRow + 1),
- currentCol);
- if (moveStatus == true) {
- currentMaze.setCell(currentRow, currentCol, ' ');
- currentRow += 1;
- facing = 'S';
- currentMaze.setCell(currentRow, currentCol,
- robotName);
- }
- }
- }
- }
- break;
- // }
- }
- return moveStatus;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement