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 7087657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:42:04+00:00 2026-05-28T07:42:04+00:00

So I’m goofing around with a prototype for a text adventure. I created a

  • 0

So I’m goofing around with a prototype for a text adventure. I created a Dictionary of availableExits in each Room object and then created an array of Room objects for the prototype. The Room (room 001) loads properly in the form, but I couldn’t access the list of available exits. After some debugging I found that the exits aren’t getting assigned to the Room objects. Anyone know what I am doing wrong here?

Summary of code:

public RoomManager()
{
    //available exits for each room
    Dictionary<string, int> room1Exits = new Dictionary<string, int>();
    room1Exits.Add("E", 002);
    room1Exits.Add("S", 003);
    Dictionary<string, int> room2Exits = new Dictionary<string, int>();
    room2Exits.Add("S", 004);
    room2Exits.Add("W", 001);
    Dictionary<string, int> room3Exits = new Dictionary<string, int>();
    room3Exits.Add("N", 001);
    room3Exits.Add("E", 004);
    Dictionary<string, int> room4Exits = new Dictionary<string, int>();
    room4Exits.Add("N", 002);
    room4Exits.Add("W", 003);

    listOfRooms = new Room[5];
    listOfRooms[0] = new Room(0, "How the hell did you get here!?!", room1Exits);
    listOfRooms[1] = new Room(001, room1Desc, room1Exits);
    listOfRooms[2] = new Room(002, room2Desc, room2Exits);
    listOfRooms[3] = new Room(003, room3Desc, room3Exits);
    listOfRooms[4] = new Room(004, room4Desc, room4Exits);
}  

…

public class Room
{
    //Init Variables
    int roomNumber;
    string roomDescription;
    //Dictionary - index N,E,S,W will use room# for available exits and 000 for no exit
    Dictionary<string, int> availableExits = new Dictionary<string, int>();

    //Constructor
    //Need a Roomnumber, Room Description, and avilable exits
    public Room(int roomIndex, string basicRoomDescript,
                Dictionary<string, int> availableExits)
    {
        roomNumber = roomIndex;
        roomDescription = basicRoomDescript;
    }

    //Properties

    //Returns which exits can be chosen
    public Dictionary<string, int> AvailableExits
    {
        get { return availableExits; }
        set { AvailableExits = availableExits; }
    }
}   

…

public partial class Form1 : Form
{
    RoomManager level;
    Player player;
    //string CurrentRoom;
    Room CurrentRoom;
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, System.EventArgs e)
    {
        level = new RoomManager();
        player = new Player("Victor", 001);
        CurrentRoom = level.RoomList[player.PlayerLocation];
        lblRoom.Text = "Room#: " + player.PlayerLocation;
        txtDesc.Text = CurrentRoom.GetRoomDescription();

        //Check for available exits and enable/disable buttons as needed
        this.SetExits();
    }

    //Private Methods

    private void SetExits() //might need to feed player and current room objects
    {
        if (!CurrentRoom.AvailableExits.ContainsKey("N"))
        { btnNorth.Enabled = false; }
        if (!CurrentRoom.AvailableExits.ContainsKey("E"))
        { btnEast.Enabled = false; }
        if (!CurrentRoom.AvailableExits.ContainsKey("S"))
        { btnSouth.Enabled = false; }
        if (!CurrentRoom.AvailableExits.ContainsKey("W"))
        { btnWest.Enabled = false; }
    }
}

I’ve posted the project here. The code is really rough, I just hacked it up this morning and haven’t done any review or cleaning yet. Any and all help/advice is appreciated.

  • 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-05-28T07:42:05+00:00Added an answer on May 28, 2026 at 7:42 am

    You have a local variable called availableExits in your Room class and you pass in a parameter called availableExits to the constructor but you never assign the local variable to the parameter passed to the constructor.

    Therefore the value of the local variable is always the empty dictionary because you did assign the local variable to be a new dictionary.

    Also your definition of the setter on the AvailableExits property appears to be recursive and would cause a StackOverflowException

    It should be as follows:

    public Dictionary<string, int> AvailableExits
    {
        get { return availableExits; }
        set { availableExits = value; }
    }
    

    It would be better to use auto-implemented properties instead for a simple property like this.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
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'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
i got an object with contents of html markup in it, for example: string
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.