Question: Code so far: import java.util.Scanner; public class V2Skeleton { public static void main(String [] args) { Scanner input = new Scanner(System.in); char [][] grid =
import java.util.Scanner; public class V2Skeleton { public static void main(String [] args) { Scanner input = new Scanner(System.in); char [][] grid = new char [10][10]; // initialize vampire System.out.print("Enter (i, j) for vampire: "); int newI = input.nextInt(); int newJ = input.nextInt(); Creature vampire = new Creature('V', newI, newJ); // initialize human // check whether human can move System.out.print("Would you like human to move? (0: no, 1: yes): "); int isMove = input.nextInt(); // update and display grid clearGrid(grid); vampire.display(grid); drawGrid(grid); System.out.println("Vampire at: " + vampire.getI() + " " + vampire.getJ()); // get next user command System.out.print("Enter command (0 to quit): "); int command = input.nextInt(); while (command != 0) { // while not quit clearGrid(grid); vampire.update(command); vampire.display(grid); // if vampire and human are on same square, // vampire bites human, game ends // if game does not end // human makes random move // display human on grid // if vampire and human are on same square, // human sacrificed himself, game ends drawGrid(grid); System.out.println("Vampire at: " + vampire.getI() + " " + vampire.getJ()); System.out.print("Enter command (0 to quit): "); command = input.nextInt(); } // while (command != 0) } public static void clearGrid(char [][] g) { for (int i=0; i
The action takes place on a 10x 10 display grid, similar to the one you used for the Game of Life project. When the game begins, the user is prompted for the (i.j) coordinates of the vampire, and the (i, j) coordinates of the human. i and j are the row and column numbers of the position of an element in a 2-dimensional array hence, the order is reversed from the usual (x,y) coordinates. Then the user is asked if s/he would like the human to move. (It's easier to specify that the human does not move for testing the program; normally we would have the human move, of course!) The user types in commands to move the vampire. There are four commands: 1 means go left G-) 2 means go down (i+H 3 means go up ( means go right G) The vampire is not allowed to move outside the grid. You (the vampire) will try to catch the human. The human makes random moves, chosen from the ones corresponding to the four user commands. The game ends when the vampire moves onto the human's grid point and bites the human, or when the human accidentally moves onto the vampire's grid point and sacrifices himself. A sample run: libra% java V2 Enter (,j) for vampire: 5 2 Enter (, j)for human: 4 1 Would you like human to move? (0: no, 1 yes) 1 Vampire at: Human at: 1 Enter command (0 to quit):1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
