Write a java 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, described 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, described 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
To break the project down into smaller, more manageable parts, 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.
CODE TO COPY:
Answer:
Note: program is written as per user requirements.
/*** VAMPIRE HUNTING GAME IN JAVA****/
//IMPORTING PACKAGES
import java.io.*;
import java.util.*;
import java.lang.*;
//CLASS
public class HuntingGame
{
//METHOD RETURN THE RANDOM INTEGER
public static int myRand(int low,int high)
{
Random gran=new Random();
return gran.nextInt((high-low)+1)+low;
}
//METHOD RETURN THE DISTANCE
public static double findDistance(int x1,int y1,int x2,int y2)
{
double temp=Math.abs((x1-x2)*(x1-x2))+Math.abs((y1-y2)*(y1-y2));
return Math.sqrt(temp);
}
//MAIN METHOD
public static void main(String[] args)
{
//SCANNER OBJECT TO READ FROM CONSOLE
Scanner vScn=new Scanner(System.in);
//DECLARE VARIABLES
int vicX,vicY;
int cheat;
int uX,uY;
int bloodPoints;
//GENERATE RANDOM LOCATION FOR VICTIM
vicX=myRand(0,9);
vicY=myRand(0,9);
//ASKING USER WHETHER HE WOULD LIKE TO CHEAT
System.out.println("WOULD LIKE TO CHEAT:");
cheat=vScn.nextInt();
//IF USER LIKE TO CHEAT THEN PRINT THE VICTIM LOCATION
if(cheat==1)
System.out.println("The Victim is in the Location of "+ vicX +" ,"+vicY);
//INITIALIZE THE BLOOD POINTS FOR THE VAMPIRE
bloodPoints=myRand(5,10);
//INITIALIZE DISTANCE BETWEEN VAMPIRE AND VICTIM AS 1.0
double dist=1.0;
//UNTILL VAMPIRE GUESSES CORRECT LOCATION OR BLOOD POINTS ABOVE 0
while(bloodPoints>0&& dist>0)
{
//ASK THE USER TO GUESS THE VICTIM LOCATION
System.out.println("\n Enter the x and y coordinates:");
uX=vScn.nextInt();
uY=vScn.nextInt();
dist=findDistance(vicX,vicY,uX,uY);
//FIND THE DISTANCE BETWEEN VICTIM LOCATION AND GUESSED LOCATION
System.out.println("Distance between Vampire and Victim:"+dist);
int genNum=myRand(0,2);
//CHECK WHETHER AN ARRO HITS/MISSES THE VAMPIRE
if(genNum==0)
continue;
else if(genNum==1)
bloodPoints-=1;
else if(genNum==2)
bloodPoints=bloodPoints-2;
}
/* CHECK VAMPIRE WINS*/
if(dist==0)
{
System.out.println("YOU WIN");
System.exit(0);
}
if(bloodPoints==0&&dist>0)
{
System.out.println("YOU LOSE");
System.exit(0);
}
}//MAIN ENDS
}//CLASS ENDS
Write a java program that simulates the operation of a Halloween Vampire Hunt game. In the...
Write a Java application program that plays a number guessing game with the user. In the starter code that you are given to help you begin the project, you will find the following lines of code: Random generator = args.length == 0 ? new Random() : new Random(Integer.parseInt(args[0])); int secret = generator.nextInt(100); You must keep these lines of code in your program. If you delete these lines, or if you change thse lines in any way, then your program...
Has to be written in C++. Visual studio. Write a C++ program to realize the game of guessing the number. Generally, the game will generate a random number and the player has to find out the number. In each guess, the program will give you a feedback as your guess is correct, too large, or too small. Then the player play repetitively until find out the number. Specifically, the game plays as the following. a). When the game is started,...
In C... Write a program to simulate a pick-5 lottery game. Your program must generate and store 5 distinct random numbers between 1 and 9 (inclusive) in an array. The program prompts the user for: an integer random seed five distinct integers between 1 and 9 (which are stored in another array) The program then compares the two arrays to determine if they are identical. If the two arrays are identical, then the user wins the game. otherwise the program...
**IN JAVA** Make a Game -Game Strategy The program and the user alternate turns, picking up one, two, or three straws on each turn. The program goes first. The player to pick up the last straw loses. -Game process Your program should start by generating and displaying a random integer (which represents the number of straws) between 10 and 20 inclusive. If this number is 1 more than a multiple of 4, add 1. For example, if the random integer...
Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...
Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...
JAVA Hangman Your game should have a list of at least ten phrases of your choosing.The game chooses a random phrase from the list. This is the phrase the player tries to guess. The phrase is hidden-- all letters are replaced with asterisks. Spaces and punctuation are left unhidden. So if the phrase is "Joe Programmer", the initial partially hidden phrase is: *** ********** The user guesses a letter. All occurrences of the letter in the phrase are replaced in...
For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...
This program will implement a simple guessing game... Write a program that will generate a random number between 1 and 50 and then have the user guess the number. The program should tell the user whether they have guessed too high or too low and allow them to continue to guess until they get the number or enter a 0 to quit. When they guess the number it should tell them how many guesses it took. At the end, the...
Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...