Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Must be in java You will make a simple game where the user creates a wild jungle and navigates around the world exploring various animals

Must be in java

You will make a simple game where the user creates a wild jungle and navigates around the world exploring various animals and adding them to the observed animals list!

Here are the instructions:

At the beginning of the program, introduce the program and explain to the user how the game works:

Welcome to the jungle world creator!

In this game, you will be inserting animals in certain places in the world that you create! You will also be allowed to remove animals from certain locations before you start exploring!

Once you start exploring, you will navigate around the world to observe the animals that you have inserted.

The game will keep track of all the animals you have observed!

You will be using 3 parallel two-dimensional arrays for this program as well as a 1D array:

2D String array to create the visible world the user navigates in.

2D String array that keeps track of animals in the world.

2D boolean array that keeps track of whether the spot was explored or not.

1D String array to keep track of observed animals. Its length should be the length of world*width of the world.

Notes:

Make sure to initialize all the values in the boolean array to false, except the starting position (0,0) is set to true.

Make sure to initialize all the values in the animalWorld and observedAnimals array to be because otherwise it will be initialized to null and you need to deal with it using if statements.

Make the 2D boolean array a global variable and initialize it only in the main method.

You must have the following methods created and used within your program:

makeWorld(String[][] world, int posX, int posY) ? This methods basically sets up the visible world. Assigning * to unexplored areas and O to explored areas. It also sets the users current position: (posX,posY) to a string of your choosing, example x. At the end of the method and after assigning new Strings using loops and if statements, it returns the 2D String array world.

printMainMenu()? Prints:

1. Insert an animal into the world

2. Remove an animal from the world

3. Explore the world

printMoveMenu() ? Prints:

W. Move Forward

A. Move Left

S. Move Backward

D. Move Right

I. Display observed animals

N. Sort the observed animals list by alphabetical order

E. Exit

insertAnimalToWorld(String[][] animalLocations) ? Prompts the user to enter the x and y coordinate as well as their desired animal name and inserts it to the world in the location [x,y]as long as:

- The x and y coordinates are in the worlds boundaries

- The area [x,y] is not occupied by another animal

If the conditions are not met prompt the user to enter the coordinates as well as the animal name again until the conditions above are met.

removeAnimalFromWorld(String[][] animalLocations)? Prompts the user to enter the x and y coordinate and removes the animal from the world in the location [x,y] as long as:

- The x and y coordinates are in the worlds boundaries

- The area [x,y] is not empty (contains an animal)

If the conditions are not met prompt the user to enter the coordinates until the conditions above are met.

Hint: To remove the animal you can just set the String at [x,y] to .

isEmptyBlock(String[][] animalWorld, int x, int y) ? Returns false if the array has an animal at [x,y] and true if [x,y] is empty.

updateObservedAnimals(String[] observedAnimals, String animal) ? adds animal into the observedAnimals array into the first occurrence of an empty String and returns the observedAnimals array.

printWorld(String[][] world) ? Prints the world in a grid/tabular format.

move(String[][] world, int x, int y, String[] observedAnimals, String[][] animalLocations) ? This method calls the makeWorld method to create a new world with the new user position and sets the 2D boolean array at [x,y] to be true, setting this area as explored. If [x,y] has an animal display the animal name and add it to the observed animals list and print the observed animals list, otherwise display you did not encounter anything :( . This method returns world at the end.

explore(String[][] world, String[][] animalLocations, String[] observedAnimals) ? Starts the exploration! This method prints out the world and then the move menu and asks the user to choose from the move menu until the user chooses to exit. In this method, make sure to declare the x and y variables that keep track of the users position in the world. When the user chooses to move forward for example, change the x and y values accordingly and make sure they are within the worlds bounds, if they are, call the move method and print the world, otherwise reset the position to 0,0 and tell the user that they went off bounds.

printObservedAnimals(String[] observedAnimals) ? Prints the observedAnimals list by printing each animal on one line separated by a space.

isExplored(int x, int y) ? Returns true if [x,y] is explored and false if [x,y] is not explored.

sortAnimalList(String[] observedAnimals) ? Sorts the observedAnimals list in alphabetical order using either the Bubble Sort or Selection Sort algorithms. You are NOT allowed to use Arrays.sort() for this method.

You are also free to use any additional methods if you choose to.

This is all I have so far complete the rest.

public class three {

static Scanner input = new Scanner(System.in);

static int x = 0, y = 0;

static int prevX = 0, prevY = 0;

private static Object[][] updateworld;

public static void main(String[] args) {

String[][] animalLocations = { { "" }, { "" } };

String[][] observedAnimals = { { "" }, { "" } };

int posX = 0, posY = 0;

// displays instructions

instructions();

String[][] world = makeWorld();

worldCreate(world);

// display menus

updateWorld(world);

printMainMenu();

//printWorld(world);

int menuAnswer = input.nextInt();

if(menuAnswer == 1){

insertAnimalToWorld(world);

}

else if (menuAnswer == 2) {

removeAnimalFromWorld(world);

}

else {

System.out.println("Welcome to the world explorer!");

printMoveMenu();

}

}

public static String[][] makeWorld() {

// prompt user to enter length and width of the world

System.out.println("Enter the dimensions of your jungle!");

System.out.println("Enter length: ");

int column = input.nextInt();

System.out.println("Enter width: ");

int row = input.nextInt();

return new String[row][column];

}

// instructions

public static void instructions() {

System.out.println("Welcome to the jungle world creator! " +

"In this game, you will be inserting animals in certain places in the world that you create! You will also be allowed to remove animals from certain locations before you start exploring! " +

"Once you start exploring, you will navigate around the world to observe the animals that you have inserted. " +

"The game will keep track of all the animals you have observed! ");

}

// printing main menus

public static void printMainMenu() {

System.out.println("1. Insert an animal into the world");

System.out.println("2. Remove an animal from the world");

System.out.println("3. Explore the world");

}

// printing the world

public static void printWorld(String[][] arrayIn) {

for (int row = 0; row < arrayIn.length; row++) {

for (int column = 0; column < arrayIn[row].length; column++) {

System.out.print(arrayIn[row][column] + " ");

}

System.out.println();

}

}

// starting exploration

public static void explore(String[][] world, String[][] animalLocations, String[][] observedAnimals) {

System.out.println("Welcome to the world explorer!");

}

// initialize the world

public static void worldCreate(String[][] world) {

for (int column = 0; column < world.length; column++) {

for (int row = 0; row < world[column].length; row++) {

world[column][row] = "*";

}

}

}

public static void updateWorld(String[][] world) {

world[prevX][prevY] = "O";

world[x][y] = "X";

prevX = x; prevY = y;

printWorld(world);

}

// printing move menu

private static void printMoveMenu() {

System.out.println("W. Move Forward");

System.out.println("A. Move Left");

System.out.println("S. Move Backward");

System.out.println("D. Move Right");

System.out.println("I. Display observed animals");

System.out.println("E. Exit");

String moveAnswer = input.next();

}

public static void insertAnimalToWorld(String[][]animalLocations) {

System.out.println("Enter your desired (x,y) coordinate to add animal");

int coordinate1 = input.nextInt();

int coordinate2 = input.nextInt();

System.out.println("What kind of animal would you like to add?");

String animal = input.next();

int[][] updateworld = new int[coordinate1][coordinate2];

//System.out.println(coordinate1 + updateworld.length + updateworld[0].length);

for (int row = 0; row < updateworld.length; row++) {

for (int column = 0; column < updateworld[row].length; column++) {

updateworld[row][column] = input.nextInt();

}

}

}

public static void removeAnimalFromWorld(String[][]animalLocations) {

System.out.println("Enter the desired (x,y) coordinate to remove animal");

int coordinate3 = input.nextInt();

int coordinate4 = input.nextInt();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning PostgreSQL On The Cloud Simplifying Database As A Service On Cloud Platforms

Authors: Baji Shaik ,Avinash Vallarapu

1st Edition

1484234464, 978-1484234464

More Books

Students also viewed these Databases questions

Question

7. What does practice at spontaneity and improvisation look like?

Answered: 1 week ago

Question

Conduct a needs assessment. page 269

Answered: 1 week ago