import java.util.*; public class ChaseDriver { public static void main (String [] args) { Scanner in = new Scanner(System.in); int pRow; int pColumn; Chase aChase = new Chase(); char answer = ' '; aChase.display(); while ((answer != 'q') && (answer != 'Q')) { System.out.print("Enter player row: "); pRow = in.nextInt(); System.out.print("Enter player column: "); pColumn = in.nextInt(); in.nextLine(); aChase.placePlayer(pRow,pColumn); System.out.println("Before chase"); aChase.display(); // Part II: Determine the monster's destination coordinates so it 'chases' the // player aChase.determineDestination(pRow,pColumn); // Part I: Once destination (row,column) known move the monster from location to // another. aChase.move(); System.out.println("To see chase: Hit enter to continue"); in.nextLine(); aChase.display(); System.out.print("Enter 'q' to quit: "); answer = in.nextLine().charAt(0); } } } // Student version: // Part 1: Movement not implemented // Part 2: Chase not implemented class Chase { public static final int SIZE = 4; public static final char PLAYER = 'P'; public static final char MONSTER = 'M'; public static final char EMPTY = ' '; private char maze[][]; private int mRow; private int mColumn; private int dMRow; private int dMColumn; public Chase () { int r; int c; int temp; Random aGenerator = new Random(); maze = new char[SIZE][SIZE]; for (r = 0; r < SIZE; r++) for (c = 0; c < SIZE; c++) maze[r][c] = EMPTY; mRow = aGenerator.nextInt(SIZE); mColumn = aGenerator.nextInt(SIZE); maze[mRow][mColumn] = MONSTER; dMRow = -1; dMColumn = -1; } public void display () { int r; int c; System.out.println(" 0 1 2 3"); for (r = 0; r < SIZE; r++) { System.out.println(" - - - -"); System.out.print(r + " "); for (c = 0 ; c < SIZE; c++) { System.out.print("|" + maze[r][c]); } System.out.println("|"); } System.out.println(" - - - -"); } // Part I: Given that the source and destination row,column // known move the monster from it's current to destination // location. public void move () { } // Part II: Determine destination: updated the dMRow, dMColumn values so // it 'chases' the player public void determineDestination(int pRow, int pColumn) { } public void placePlayer (int r, int c) { maze[r][c] = PLAYER; } }