I need help with creating the room class and dungeon class, i keep going back and forth and now I am just confusing myself.
DUNGEON ADVENTURE

PROGRAM PURPOSE:

The purpose of this is assignment is for you to practice working with two dimensional arrays as well as to continue developing your skills at working with multiple classes. The code that you write for this assignment will be used in Assignment 3. It is imperative you get the program working, since Assignment 3 directly depends on it.

For this assignment, you will design 4 classes. The details of the classes are provided below.

PROGRAM DETAIL:

This is an adventure game where a hero is randomly placed within a dungeon that is a 5 x 5 2D array. The hero needs to find the two pieces of the Crown of Coding, and take them to the exit to win the game. Some features of the dungeon will prove a hindrance to the hero's task (pits), while some will prove helpful (healing potions). Your task is to write a correct Java program that will simulate this adventure. NOTE: You are welcome to implement a variation on this theme provided you adhere to the spirit of what is being asked on this assignment.

CLASS DETAILS:

Room.java

Contains default constructor and all methods you deem necessary -- modular design is CRUCIAL

Contains the following items/behaviors

(Possibly a) Healing Potion - heals 5-15 hit points (this amount will be randomly generated -- you can modify the range)

(Possibly a) Pit - damage a pit can cause is from 1-20 hit points (this amount will be randomly generated - you can modify the range)

(Possibly an) Entrance - only one room will have an entrance and the room that contains the entrance will contain NOTHING else

(Possibly an) Exit - only one room will have an exit and the room that contains the exit will contain NOTHING else

(Possibly a) Crown Piece - two pieces in game and they will never be in the same room

Doors - N, S, E, W

10% possibility (this is a constant that you can modify) room will contain a healing potion, vision potion, and pit (each of these are independent of one another)

Extra Credit (for individuals, required for teams) Vision Potion - can be used to allow user to see eight rooms surrounding current room as well as current room (location in maze may cause less than 8 to be displayed)

Must contain a toString method that builds a 2D Graphical representation of the room (NOTE: you may use any graphical components in Java that you wish). The (command line) representation is as follows:



      • will represent a north/south door (the - represents the door). If the room is on a boundary of the maze (upper or lower), then that will be represented with ***

East/west doors will be represented in a similar fashion with the door being the | character as opposed to a -.

In the center of the room you will display a letter that represents what the room contains. Here are the letters to use and what they represent:

M - Multiple Items

P - Pit

I - Entrance (In)

O - Exit (Out)

V - Vision Potion

H - Healing Potion

E - Empty Room

Example: Room 1,1 might look like
* - *
| P |
* - *

Room 0,0 might look like
* * *
* E |
* - *

Hero.java

Contains an explicit value constructor for the name of the hero

Contains at least the following:

Hit Points - initially set to 75 - 100 upon creation (randomly generate - you can change the range)

The number of Healing Potions

The number of Vision Potions

The number of Crown Pieces found

Moves the Hero around the Dungeon

Increases or decreases the Hit Points accordingly

Contains a toString method that builds a String containing:

Name

HitPoints

Total Healing Potions

Total Vision Potions

Total Crown Pieces Found

NOTE: The Hero and the Dungeon will need to interact. When the Hero walks into a room if there is a potion in the room, the Hero automatically picks up the potion. Likewise if there is a pit in the room, the Hero automatically falls in the pit and takes a Hit Point loss. All of these changes obviously affect the room. For example, the Hero walks into a room that contains a Healing Potion. The Hero will pick up the potion, changing the Hero's potion total, as well as changing the room's potion total.

Dungeon.java

Creates/contains a 5 X 5 2D Array of Rooms (you can make this larger if you wish)

Places the Entrance, the Exit, and the Crown Pieces. NOTES: the entrance and exit are empty rooms. The crown pieces can not be at the entrance or the exit, or in the same room.

Maintains location of the Hero in the Dungeon

Contains a toString method that builds a String containing information about the entire dungeon. This is CHALLENGING.

DungeonAdventure.java

Contains the main method

Provides an introduction to the game describing what the game is about and how to play

Creates a Dungeon Object and a Hero Object

Does the following repetitively:

Prints the current room (this is based on the Hero's current location)

Determines the Hero's options (Move, Use a Potion)

Continues this process until the Hero wins or dies

NOTE: Include a hidden menu option for testing that prints out the entire Dungeon -- specify what the menu option is in your documentation for the DungeonAdventure class. Also include a hidden menu option to add 1000 hit/health points to the user. SIDE NOTE: you might want to include other cheats to make game testing easier.

At the conclusion of the game, display the entire Dungeon

Recommended Answers

All 3 Replies

What specific java coding questions do you have? Can you post the code and ask your questions?

This is what I have for my Room class. I commented out what I initially had. I am getting confused on how to create a Room object but then create a 5x5 TwoD array of type Room. I thought I was creating a 5x5 array in the Room class, but now I think thats wrong because I am suppose to just construct a Room with the possible components and then create a 5x5 TwoD array of type Room in the Dungeon class and then create a Dungeon object in the DungeonAdventure class. I dont get how to just construct the Room with the possibility of these objects and then fill it in the Dungeon class.

import java.util.Random;
public class Room
{
    private Random random = new Random();
    private int hp;
    private int pit;
    private Room entrance;
    private Room exit;
    private int cp1, cp2;
    private Room [][] room = new Room[5][5];

    public Room(int hp, int pit, Room entrance, Room exit, int cp1, int cp2)
    {
        int num = random.nextInt(101);
        this.entrance = entrance;//room[random.nextInt(5)][random.nextInt(5)];
        this.exit = exit;//room[random.nextInt(5)][random.nextInt(5)];

        if(!this.entrance.equals(room) || !this.exit.equals(room))
        {
            if(num <= 10)
                this.hp = random.nextInt(10 - 1) + 5;

            int num1 = random.nextInt(101);
            if(num1 <= 10)
                this.pit = pit;

            this.cp1 = cp1;
            if(!this.cp1.equals(room))
                this.cp2 = cp2;
        }






    }//end DVC
}//end class

I am suppose to just construct a Room with the possible components and then create a 5x5 TwoD array of type Room in the Dungeon class and then create a Dungeon object in the DungeonAdventure class.

Looks like you are heading in the right direction. You need an array of 4 (possible) doors in tthe Room class...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.