/* * @topic W020131 Maze: Java application * @brief class Visitor */ package mazeapp; import java.util.Scanner; public class Visitor { Scanner sc; private int direction; private char action; // constructor public Visitor() { sc = new Scanner(System.in); direction = MazeUtility.WEST; action = MazeUtility.GO; } // operations public int turnLeft() { if (direction == MazeUtility.WEST) { direction = MazeUtility.SOUTH; } else if (direction == MazeUtility.NORTH) { direction = MazeUtility.WEST; } else if (direction == MazeUtility.EAST) { direction = MazeUtility.NORTH; } else if (direction == MazeUtility.SOUTH) { direction = MazeUtility.EAST; } return 0; }//turn_left() public int turnRight() { if (direction == MazeUtility.WEST) { direction = MazeUtility.NORTH; } else if (direction == MazeUtility.NORTH) { direction = MazeUtility.EAST; } else if (direction == MazeUtility.EAST) { direction = MazeUtility.SOUTH; } else if (direction == MazeUtility.SOUTH) { direction = MazeUtility.WEST; } return 0; }//turn_right() //-------------------------------------------------- // ask the visitor what they want to do //-------------------------------------------------- public int askForAction() { System.out.println("What would you like to do? (L R G)\n"); // get user input from the keyboard -- // ask scanner for a string, but then // extract first character and remeber it: action = sc.next().charAt(0); if (action == 'L') { turnLeft(); } if (action == 'R') { turnRight(); } return 0; }//get_visitor_action() public char getLastAction() { return action; } public int getDirection() { return direction; } }//class Visitor