You will be creating a text-only version of a game called Hurkle. Hurkle, a happ
ID: 665507 • Letter: Y
Question
You will be creating a text-only version of a game called Hurkle. Hurkle, a happy little beast, lives on the planet Lirht which is a flat world divided into 10 rows and columns. The Hurkle likes to hide randomly in one of those 100 plots on Lirht. It is the user's job to find the Hurkle. The player will enter a horizontal (x) coordinate, followed by a vertical (y) coordinate. The Hurkle will then give a clue as to where it is hiding. Here is a typical playing sequence (without the grid output):
Guess Clue
5, 5 Go Northwest
2, 7 Go Northeast
3, 9 Go South
3, 8 You found Hurkle!
Begin by displaying Lirht:
NORTH
--- --- --- --- --- --- --- --- --- ---
10 | | | | | | | | | | |
--- --- --- --- --- --- --- --- --- ---
9 | | | | | | | | | | |
--- --- --- --- --- --- --- --- --- ---
8 | | | | | | | | | | |
--- --- --- --- --- --- --- --- --- ---
7 | | | | | | | | | | |
W --- --- --- --- --- --- --- --- --- --- E
E 6 | | | | | | | | | | | A
S --- --- --- --- --- --- --- --- --- --- S
T 5 | | | | | | | | | | | T
--- --- --- --- --- --- --- --- --- ---
4 | | | | | | | | | | |
--- --- --- --- --- --- --- --- --- ---
3 | | | | | | | | | | |
--- --- --- --- --- --- --- --- --- ---
2 | | | | | | | | | | |
--- --- --- --- --- --- --- --- --- ---
1 | | | | | | | | | | |
--- --- --- --- --- --- --- --- --- ---
1 2 3 4 5 6 7 8 9 10
SOUTH
Each time the player makes a guess, reprint Lirht with X's in the spots guessed. To make it a little easier, you don't need to include the directions (North, South, etc.)
Java JCreator
Explanation / Answer
Answer:
/********Java Program for Hurkle.java**********/
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Hurkle huk=new Hurkle();
huk.InitializeLihrtBoard();
huk.playHurkle();
}
}
/********* Hurkle Class*************/
class Hurkle
{
int guess_m,guess_n;
int[][] LihrtBoard=new int[10][10];
public Hurkle()
{
guess_n=0;
guess_m=0;
}
public void InitializeLihrtBoard()
{
for(int k1=1;k1<=10;k1++)
{
for(int k2=1;k2<=10;k2++)
{
LihrtBoard[k1][k2]=0;
}
}
}
public int getGuessRandomMoveN()
{
Random a_rand=new Random();
int a_n=a_rand.nextInt((10-1)+1)+1;
return a_n;
}
public int getGuessRandomMoveM()
{
Random a_rand=new Random();
int a_m=a_rand.nextInt((10-1)+1)+1;
return a_m;
}
public void displayLihrt()
{
for(int k1=10;k1<=1;k1--)
{
System.out.println("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ");
System.out.print("|");
for(int k2=1;k2<=10;k2++)
{
printLihrtCell(LihrtBoard[k1][k2]);
System.out.print("|");
}
}
System.out.println("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ");
}
public void printLihrtCell(int cell_value)
{
switch(cell_value)
{
case 1:
System.out.print("X");
break;
default:
System.out.print(" ");
break;
}
}
public void playHurkle()
{
boolean isHurkleFound=false;
displayHurkle();
do
{
guess_m=getGuessRandomMoveM();
guess_n=getGuessRandomMoveN();
LihrtBoard[guess_m][guess_n]=1;
if(guess_m==5&&guess_n==5)
System.out.println("Go Northwest");
if(guess_m==2&&guess_n==7)
System.out.println("Go Northeast");
if(guess_m==3&&guess_n==9)
System.out.println("Go South");
if(guess_m==3&&guess_n==8)
{
System.out.println ("You found Hurkle!");
isHurkleFound=true;
}
displayLihrt();
}while(!isHurkleFound);
}
}//class Hurkle ends
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.