Modeling the caves

Assignment Help JAVA Programming
Reference no: EM1341858

Assignment 2 Description

You are a mighty warrior, and armed with your trusty bow and 3 arrows, you enter The Caves in search of the mighty Wumpus. If you shoot the Wumpus, you are victorious and the masses will praise you, but if you stumble upon the Wumpus unaware, it will eat you! Also, beware of the webs of the giant poisonous spiders and the bottomless pits!

Your senses of smell and hearing will aid you on your quest, for the Wumpus does not bathe and can be smelled one room away. Also, the clicking mandibles of the poisonous spiders can be heard one room away, and the foul odor of a bottomless pit can be smelled one room away.

For this project, you will implement a program that lets the user play Hunt the Wumpus!

Modeling the Caves

The layout of the cave rooms is specified in a text file that looks like this (you may use this text file, but it is not required):

10

1 2 6 10

A wooden sign reads "Beware of the Wumpus!"

2 1 3 7

There is a black pool of water in the corner.

3 2 4 8

You see a Tyrannosaurus Rex fossil embedded in the wall.

4 3 5 9

There is an empty Diet Rite can here.

5 4 6 10

You almost step on a broken cellular phone.

6 1 5 7

A couple of evil rats stare at you from under a pile of rocks.

7 2 6 8

You find a Spanish doubloon on the floor.

8 3 7 9

The ceiling is very low and you have to stoop.

9 4 8 10

You step on a slippery spot, slip, and fall on your keester.

10 1 5 9

You get a strong sense of deja vu.

The first line of the text file gives the number of rooms in the caves (your program should handle any number of rooms). Each room is described on two lines: the first gives the room number, the room numbers of the three adjacent rooms (there are always 3); the second gives a string that describes the room.

Put this cave layout (or one in a similar format) into a text file. Declare a class to represent a single cave room (Room), and then declare an array of rooms to hold the entire cave in your main program. One of the first things your program should do is open and read the layout file and put the information into your array of rooms.

 

Your program should then pick random numbers to figure out where to place the Wumpus, the two spider rooms (in two different rooms), and the bottomless pit. Make sure nothing ends up in room #1, as that is where the player starts, and don't put spiders, the Wumpus, or a pit in the same room together.

Playing the game

Here is a sample game. Comments in italics are not visible to the player, but are there to help explain what is happening. The user's input appears in boldface.

Welcome to **Hunt The Wumpus!**

You are in room 1.

You have 3 arrows left.

A wooden sign reads "Beware of the Wumpus!"

There are tunnels to rooms 2, 6, and 10.

You hear a faint clicking noise. (There are spiders in room 6)

(M)ove or (S)hoot?

M

Which room?

5

Dimwit! You can't get to there from here.

There are tunnels to rooms 2, 6, and 10.

(M)ove or (S)hoot?

M

Which room?

2

You are in room 2.

You have 3 arrows left.

There is a black pool of water in the corner.

There are tunnels to rooms 1, 3, and 7.

You smell a dank odor. (There is a pit in room 3)

You smell some nasty Wumpus! (The Wumpus is in room 7)

(M)ove or (S)hoot?

S

Which room?

3 (The user picks the wrong room)

Your arrow goes down the tunnel and is lost. You missed.

You are in room 2.

You have 2 arrows left.

There is a black pool of water in the corner.

There are tunnels to rooms 1, 3, and 7.

You smell a dank odor.

You smell some nasty Wumpus!

(M)ove or (S)hoot?

S

Which room?

7

Your arrow goes down the tunnel and finds its mark!

You shot the Wumpus! ** You Win! **

Enjoy your fame!

 

After the caves are all set up, the game proceeds. Have an integer (perhaps called currentRoom) to keep track of which room the warrior/player is in currently. Your program will then repeat the following loop:

1. Display the information about the current room. Print the room number, its description, and the list of adjacent rooms. Also check if any of the adjacent rooms have spiders, a pit, or the Wumpus and print a smell/hear message as appropriate. (If adjacent to two pits, only print one smelly message.) You might also display the number of remaining arrows.

2. Ask the player if he/she wants to move or shoot.

3. If the player shoots, have her/him pick which of the adjacent rooms to shoot into. If that room contains the Wumpus, the player wins and the game is over. If not, reduce the number of arrows by one. If the player runs out of arrows, they lose.

4. If the player moves, ask for the room number and change room. If the new room contains spiders, a pit, or the Wumpus, the game is over.

Do not let the user move or shoot into a room that is not adjacent to the current room.

Additional Requirements

On the first line of the cave layout file, after the number of rooms, have your program accept the number of spider rooms and bottomless pits. Thus, if the first line was

 

25 5 3

your cave would have 25 rooms, with 5 of those having poisonous spiders, and 3 rooms with pits. These rooms are still chosen randomly.

? Add a supply room that contains arrows. If the player enters this room, their arrows are refilled back to 3. Note that the game does not end if the player runs out of arrows.

? Add a room (chosen at random) with giant bats. If the player enters that room, the bats pick him/her up and fly to a random room before dropping the player (unharmed). If the new random room has the Wumpus, a pit, or spiders, the game is over. The bats should move the player out of the room they are in.

 

Notes

1. Before you begin programming, sketch a high level design of what you want to implement using the UML notation. At the very least, you should have a use case diagram, class diagram (for the Room class) and a sequence diagram (for the game loop - 4 steps described above).

2. Remember to include comments at the top of your program and 1-2 lines for each function/method (for pre- and post-conditions). Make them javadoccompatible.

3. Think carefully about how you design your room class. If you do it well, this is not a hard program to write.

4. Write this program in pieces. First, type up the layout text file and write a program to simply read in the file and print the cave info on the screen so you know it is reading correctly. Then, you might try to set up the program so the player can move around, but there are no monsters or pits.

5. Start right away!

Hand In

Email me), in a single MS Word document with the following four clearly defined sections:

1. Listing (print-out) of your nicely formatted program source code (with comments and headers)

2. Print-out of the text file that contains your cave layout

3. Screen captures of at least three sample runs/scenario output

4. High level design using UML notation (minimum of use case diagram, class diagram for Room class, & sequence diagram for game loop as described in the four steps above)

5. Utilize the submission template provided in the course module.

Source code listing here.... 

/*******************************************************************************

 * Room Class

 *

 * Description here....

 *

 * Preconditions:

 * Postconditions:

 *

 * @authorStudent Name

 * @date

 * @version 1.0

 *

 ******************************************************************************/

publicclass Room {

 

declarations here...

 

       public Room(...) {

 

              logic here...

       }

 

       /*******************************************************************************

        * method

        *

        * Description here...

        *

        * Preconditions:

        * Postconditions:

        *

        * @authorStudent Name

        * @date

        * @version 1.0

        * @param ...

        * @return ...

        ******************************************************************************/

 

       publicvoidmethod() {

              logic

       }

 

       // sample method    

       publicbooleancheckWumpus() {

              returnwumpus;

       }

 

       // sample method    

       publicvoidsetSpiders() {

              spiders = true;

              enemy = true;

       }

 

       // sample method

       publicbooleancheckSpiders() {

              returnspiders;

       }

 

       // sample method    

       publicvoidsetPit() {

              pit = true;

              enemy = true;

       }

 

       // sample method

       publicbooleancheckPit() {

              returnpit;

       }

 

       // sample method    

       publicbooleancheckEnemy() {

              returnenemy;

       }

 

       // sample method    

       public String getDescription() {

              returndescription;

       }

 

       // sample method    

       publicintgetRoomNumber() {

              returnroomNumber;

       }

 

More methods here...

}

 

 

/*******************************************************************************

 * Game Class

 *

 * Description here....

 *

 * Preconditions:

 * Postconditions:

 *

 * @authorStudent Name

 * @date

 * @version 1.0

 *

 ******************************************************************************/

 

publicclass Game {

 

       publicstaticvoid main(String[] args) throwsIOException {

 

 

              FileReader r = newFileReader("cave.txt");

              Scanner s = new Scanner(r);             

 

Logic here...       

Place screen captures here of at least 3 runs (different scenarios) of your program (be sure they are readable).

Insert text file here...

Insert UML design diagrams here (use case, class, and sequence diagram)...

Reference no: EM1341858

Write a class array that encapsulates an array

Write a class Array that encapsulates an array and provides bounds-checked access. The private instance variables should be int index and inarray[10]. The public members shoul

Write program that will store the lakers roster in an array

Write a program that will store the Lakers (or your favorite basketball team) roster in an array. You will then loop through the array to display each player and their info

Square matrix of dimension

You are given a square matrix of dimension N. Let this matrix be called A. Your task is to rotate A in clockwise direction byS degrees, where S is angle of rotation. On the

What is the benefit of using layout managers

What is the benefit of using layout managers? When a mouse event is generated how is the location of the click point determined? What layout manager should you use so that eve

Delete a random element from an arraylist

Elements in an ArrayList and picking one at random to remove. Unfortunately, this slow, since deleting a random element from an ArrayList is slow because of all the shifting

Problem regarding the initializing static fields

Why do static ?elds of a class have to be initialized when the class is loaded? Why can't we initialize static ?elds when the program starts? Give an example of what goes wr

What is the smallest exponent

In storing number in a string of 16 bits, the first bit is used for the sign of the number, and the next 5 bits store the exponent plus the bias, and the remaining 10 bits s

Gui that accepts user input of the amount of the mortgage

Please help write a java program using a graphical user interface that accepts user input of the amount of the mortgage, the term of the mortgage and the interest rate of th

Reviews

Write a Review

 
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd