Question: Introduction In this exercise, we are once again exploring the grim world of fantasy adventure gaming. This time you will be generating procedural dungeons using

Introduction
In this exercise, we are once again exploring the grim world of fantasy adventure gaming. This time you will be generating procedural dungeons using the power of arrays and random numbers.
Random numbers
There are a few different ways to generate random numbers in Java. For this exercise, we are going to use an oldie but a goodie.
import java.util.Random;
class DungeonsOfDoom {
public static final Random rng = new Random();
public static void main(String[] args){
// generate a random number between 0 and 9
int randInt = rng.nextInt(10);
}
}
The Random.nextInt() method returns a random number between 0 and the specified upper bound. The upper bound will NOT be returned. This makes it extremely useful for returning a random array index.
The Mission
Declare data
Declare three initialized arrays. These should include:
An array of at least 4 room names.
An array of at least 4 monster names
An array of at least 4 treasure names
Generate random encounter
Create a method that will select a random item from each array. Return a three-element array from this function. The room name should be at index 0, the monster name at index 1, and the treasure name at index 2. Declare and use constants for these array indices.
Display an encounter
Create a method that takes a three-element array of strings and uses it to print out a description of the encounter. Ex:
You are in a
There is a here that wants to eat you.
The is guarding a
Main game loop
Create a method that runs the main game loop. Inside the loop, Generate and display a random encounter. Then, ask the user if they want to continue. If the user enters "quit" exit the loop. Otherwise, repeat the loop.
Startup
When the program starts, print a welcome banner, then enter the main game loop.
Notes and Tips
We will be modifying and extending this program over the next two lessons. The easier your program is to maintain, the easier the follow-up exercises will be.
I recommend that you declare your data arrays and array index constants as static class member variables alongside the static number generator.
Please make sure to use array.length instead of hard coded numbers when selecting random values from arrays.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!