Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FOR JAVA Here are the instructions: At the beginning of the program, introduce the program and explain to the user how the game works: Welcome

FOR JAVA

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

E. Exit

Note: Whether the user enters I or i it should be the same thing!

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.

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

TIP:

If you get stuck, display your variables OR use debugging. See this video to learn how to use the Eclipse Debugger.

Sample Run:

Welcome to the jungle 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 you have inserted.

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

Enter the dimensions of your jungle !

Enter length: 5

Enter width: 5

1. Insert an animal into the world

2. Remove an animal from the world

3. Explore the world

Enter your choice: 1

Enter the name of the animal you would like to insert: Eevee

Enter the x coordinate of your animal 1

Enter the y coordinate of your animal 0

1. Insert an animal into the world

2. Remove an animal from the world

3. Explore the world

Enter your choice: 3

Welcome to the World Explorer!

x * * * *

* * * * *

* * * * *

* * * * *

* * * * *

W. Move Forward

A. Move Left

S. Move Backward

D. Move Right

I. Display observed animals

E. Exit

Enter your choice : S

You have encountered a/an Eevee!

Your new observed animals list is :

Eevee

O * * * *

x * * * *

* * * * *

* * * * *

* * * * *

W. Move Forward

A. Move Left

S. Move Backward

D. Move Right

I. Display observed animals

E. Exit

Enter your choice: i

Printing current observed Animals...

Eevee

W. Move Forward

A. Move Left

S. Move Backward

D. Move Right

I. Display observed animals

E. Exit

Enter your choice: e

Exiting World...

Welcome to the jungle 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 you have inserted.

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

Enter the dimensions of your jungle !

Enter length: 5

Enter width: 5

1. Insert an animal into the world

2. Remove an animal from the world

3. Explore the world

Enter your choice: 1

Enter the name of the animal you would like to insert: dog

Enter the x coordinate of your animal 2

Enter the y coordinate of your animal 0

1. Insert an animal into the world

2. Remove an animal from the world

3. Explore the world

Enter your choice: 3

Welcome to the World Explorer!

x * * * *

* * * * *

* * * * *

* * * * *

* * * * *

W. Move Forward

A. Move Left

S. Move Backward

D. Move Right

I. Display observed animals

E. Exit

Enter your choice: d

You have not encountered any animal :(

O x * * *

* * * * *

* * * * *

* * * * *

* * * * *

W. Move Forward

A. Move Left

S. Move Backward

D. Move Right

I. Display observed animals

E. Exit

Enter your choice: d

You have not encountered any animal :(

O O x * *

* * * * *

* * * * *

* * * * *

* * * * *

W. Move Forward

A. Move Left

S. Move Backward

D. Move Right

I. Display observed animals

E. Exit

Enter your choice: d

You have not encountered any animal :(

O O O x *

* * * * *

* * * * *

* * * * *

* * * * *

W. Move Forward

A. Move Left

S. Move Backward

D. Move Right

I. Display observed animals

E. Exit

Enter your choice: d

You have not encountered any animal :(

O O O O x

* * * * *

* * * * *

* * * * *

* * * * *

W. Move Forward

A. Move Left

S. Move Backward

D. Move Right

I. Display observed animals

E. Exit

Enter your choice: d

You went off of bounds! Resetting the position to 0,0...

You have not encountered any animal :(

x O O O O

* * * * *

* * * * *

* * * * *

* * * * *

W. Move Forward

A. Move Left

S. Move Backward

D. Move Right

I. Display observed animals

E. Exit

Enter your choice: d

You have not encountered any animal :(

O x O O O

* * * * *

* * * * *

* * * * *

* * * * *

W. Move Forward

A. Move Left

S. Move Backward

D. Move Right

I. Display observed animals

E. Exit

Enter your choice: E

Exiting world

Welcome to the jungle 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 you have inserted.

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

Enter the dimensions of your jungle !

Enter length: 2

Enter width: 2

1. Insert an animal into the world

2. Remove an animal from the world

3. Explore the world

Enter your choice: 1

Enter the name of the animal you would like to insert: 0

Enter the x coordinate of your animal 0

Enter the y coordinate of your animal 0

1. Insert an animal into the world

2. Remove an animal from the world

3. Explore the world

Enter your choice: 2

Enter the x coordinate of the animal you want to remove: 0

Enter the y coordinate of the animal you want to remove: 1

Sorry, you cannot remove that animal because the block is empty

Enter the x coordinate of the animal you want to remove: 1

Enter the y coordinate of the animal you want to remove: 1

Out of bounds!

Enter the x coordinate of the animal you want to remove: 0

Enter the y coordinate of the animal you want to remove: 0

1. Insert an animal into the world

2. Remove an animal from the world

3. Explore the world

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

More Books

Students also viewed these Databases questions