Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7800283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:35:06+00:00 2026-06-02T00:35:06+00:00

I’m writing a Text Adventure game for a Java programming class. I’m setting up

  • 0

I’m writing a Text Adventure game for a Java programming class. I’m setting up the rooms with a parent abstract room class that each room will inherit from and configure.

For exits, a room will just invoke an .addExit() method and pass it an exit object. The game should have only one instance of every room. The exit object should have a target field pointing to one of the game’s rooms that gets initialized in the constructor.

My problem is I don’t know how to pass the exit constructor a pre-existing room reference and not a new room object. The way I see it, there are two possible ways:

  1. Directly pass the exit constructor a reference to the room instance.
  2. Have a static class that keeps track of all the room instances and has methods that returns an instance from string names or class etc.
    The exit object’s constructor is then passed a way to identify the target room, say a unique string name, which the object constructor then uses to call one of the static class’s methods that return room instances.

I’m not sure which is the best option, how to implement either option, or if there’s a better way altogether.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:35:09+00:00Added an answer on June 2, 2026 at 12:35 am

    I don’t think having a separate class for each room is a good idea. You’re probably better off with a single Room class, where each instance represents a separate room. (I know MUDs were coded this way, but even there you had “virtuals”)

    But apart from that, the question is: is Exit a property of the room or is it something that can and should be managed separately?

    The answer depends on what exactly you want to do with those Exits. If, for example you want to enforce bidirectional exits (that is, if there’s an exit from room A to B, there should be one from B to A), a separate exit management class might be appropriate. But if you need nothing more than to be able to list all the exits in a room, then move to another through one of them, they can be properties of Room.

    If you don’t know in advance, start with the simple (exits are added to each room separately), and if it doesn’t work, you can always switch to a more complex solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.