Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that simulates the operation of a Halloween Vampire Hunt game. I

ID: 3762141 • Letter: W

Question

Write a program that simulates the operation of a Halloween Vampire Hunt game.

In the game scenario, you are a vampire hunting a victim in a dark cave. The cave consists of 10 by 10 little squares, numbered 0-9 on each side; your victim is in the cave, with x-coordinate and y-coordinate 0-9 (both integers). On each turn, you guess where your victim is, and try to bite her/him.

Your “health” is determined by the number of bloodpoints you have. At the beginning, your bloodpoints are initialized to a random integer, evenly distributed from 5 to 10, inclusive.

Unfortunately, there are also vampire hunters in the cave, shooting arrows at you. (The arrows are wood, of course, for killing vampires.) On each turn, generate a random integer from 0 to 2, inclusive.

            If the random integer is 0, an arrow misses you; no damage is done

            If the random integer is 1, an arrow grazes you; you lose one bloodpoint

            If the random integer is 2, an arrow hits you; you lose two bloodpoints

The game ends when 1) you guess where your victim is and bite her/him, or 2) you are shot by too many arrows, and your bloodpoints drop to zero or below.

Your program performs these operations:

            1) generate random x and y coordinates for the victim (both integers, 0-9)

                        (use the myRand() method, defined below)

            2) ask if the user would like to cheat

            3) if the user is cheating, print the location of the victim

            4) generate initial random bloodpoints for the vampire (5 to 10, an integer)

                        (use the myRand() method, again)

            5) prompt the user to enter x and y coordinates (guess where victim is)

            6) display the distance between the vampire and victim

                        (use the findDistance() method, defined below)

            7) check whether an arrow hits/misses the vampire; update bloodpoints

                        (use the myRand() method again)

            repeat (5) – (7) until the vampire guesses the correct location of the victim, or the

            vampire’s bloodpoints drop to zero or below

Your program should produce identical output to the sample executable, when compiled and run on unixlab. (Obviously some parts of the output will be different, because of the random numbers!) Sample runs:

unixlab% java Vampire

Welcome to the vampire hunt game!

Would you like to cheat? (1 for yes, 0 for no): 0

You start with 5 blood points.

Enter your target x and y-coordinates (both 0-9): 0 2

You are 4.00 units from your victim.

You were grazed by an arrow, oops.

You have 4 blood points.

Enter your target x and y-coordinates (both 0-9): 1 2

You are 4.12 units from your victim.

You were hit by an arrow, ouch.

You have 2 blood points.

Enter your target x and y-coordinates (both 0-9): 1 1

You are 5.10 units from your victim.

You were grazed by an arrow, oops.

You have 1 blood points.

Enter your target x and y-coordinates (both 0-9): 4 4

You are 4.47 units from your victim.

You have 1 blood points.

Enter your target x and y-coordinates (both 0-9): 4 9

You are 5.00 units from your victim.

You were grazed by an arrow, oops.

Sorry, you were shot too many times; game over

unixlab% java Vampire

Welcome to the vampire hunt game!

Would you like to cheat? (1 for yes, 0 for no): 1

Victim at 7 6

You start with 10 blood points.

Enter your target x and y-coordinates (both 0-9): 7 4

You are 2.00 units from your victim.

You have 10 blood points.

Enter your target x and y-coordinates (both 0-9): 7 5

You are 1.00 units from your victim.

You were hit by an arrow, ouch.

You have 8 blood points.

Enter your target x and y-coordinates (both 0-9): 7 7

You are 1.00 units from your victim.

You were grazed by an arrow, oops.

You have 7 blood points.

Enter your target x and y-coordinates (both 0-9): 7 6

You are 0.00 units from your victim.

You bit your victim! S/he is now a vampire.

unixlab%

You must organize your program so that your main program calls two methods. The first one is myRand():

            int myRand(int low, int high)

myRand() returns a random integer from low to high (inclusive), with equal likelihood.

The second method is findDistance():

            double findDistance(int x1, int y1, int x2, int y2)

findDistance() returns the distance between the two points (x1, y1) and (x2, y2). This is defined as

sqrt [( (x1 – x2)2 + (y1 – y2)2 )]

First write the main program with some dummy methods for myRand() and findDistance(); the dummy methods just return the first argument; i.e.,

double findDistance(int x1, int y1, int x2, int y2)

{

     return x1;

}

int myRand(int low, int high)

{

     return low;

}

Then fill in the dummy methods. Each method should have a method header, including the definition and a brief description of what the method does.

For example, for iPow():

/********************************************

    int iPow(int x, int y)

    returns x to the power y

    y must be a non-negative integer

Explanation / Answer

Program code:

import java.util.*;

public class vampireHunt

{public static void main(String [] args)

{

int victimXcordinate,victimYcoordinate,p,q,k,cheatVaraible;

double distance=100;

Scanner in=new Scanner(System.in);

Random randNum=new Random();

victimXcordinate=randNum.nextInt(10);

victimYcoordinate=randNum.nextInt(10);

k=randNum.nextInt(6)+5;

System.out.println("Welcome to the vampire hunt game!");

System.out.print("Would you like to cheatVaraible? (1 for qes, 0 for no): ");

cheatVaraible=in.nextInt();

if(cheatVaraible==1)

System.out.println("You start with "+k+" blood points.");

while(k>0&&distance!=0)

{System.out.print("Enter your target x and y coordinates (both 0-9): ");

p=in.nextInt();

q=in.nextInt();

distance=findingDistance(victimXcordinate,victimYcoordinate,p,q);

System.out.printf("You are %.2f units from your victim ",distance);

if(distance==0)

System.out.println("You bit your victim! She/He is now a vampire.");

else

{k+=arrowMethod(k,randNum.nextInt(3));

System.out.println("You have "+k+" blood points");

if(k<=0)

System.out.println("Sorry, you were shot too many times; game over");

}

}

}

public static double findingDistance(int p1,int q1,int p2,int q2)

{

double x=0;

vampireHunt vh1=new vampireHunt();

x=Math.sqrt(vh1.iPow((p1-p2),2)+vh1.iPow((q1-q2),2));

return x;

}

public static int arrowMethod(int start,int num)

{switch(num)

{case 0: System.out.println("an arrow misses you; no damage is done");

return 0;

case 1: System.out.println("you are grazed by an arrow, oops;");

return -1;

case 2: System.out.println("an arrow hits you; you lose two bloodpoints");

return -2;

}

return 0;

}

int iPow(int x,int y)

{

return (int) Math.pow(x, y);

}

}

Sample output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote