I am currently working on a text-adventure type game and I am trying to use a tree to store the world data using C#. Basically each room is of the class “Room” which stores the name and description of that room as well as containing a list of attached Room’s. It has been a while since I used an OO language so this is were things get kind of fuzzy. I can load the room’s name and description from text file and instantiate a new Room object for each new room in the text file, and then I can do the same to some extend for the attachedRooms list with only a little more difficulty (made easier by having the world file indexed by room name) but then how do I ensure that there is only 1 of each room instead of making a copy each time the room is added to a room’s attachedRooms list. In C++ I could do this by instantiating all the Room objects I need and then storing pointers in the actual lists, but as far as I know C# and other managed languages don’t like pointers. Is there a good way of doing this in C# or perhaps a better way to handle my world data entirely?
If you use the new keyword in c#, you are instantiating. If not, you are essentially using a pointer. For instance, if you drag an object onto a script with an object name variable, it’s a reference. Anything in a collection is a reference. You will get a reference by using the “find” function, etc. C# is using pointers, but they are taken care of automatically.
Thanks for the clarification.