Jump to content
  • Advertisement
Sign in to follow this  
navilon

Text based game - Need Help

This topic is 4956 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am writing a text based game in C# and i am trying to figure out how to structure the code. How would i impliment objects such as a chair or a torch? Any information would help! thanks!

Share this post


Link to post
Share on other sites
Advertisement
You mean something you can interact with? You could have a .txt file with a list of objects and the text response. The objects could be denoted by a special symbol like ##, used nowhere else. Then, whenever something is inputted you could search the file for the exact string typed. I don't program in C# (yet) though so I can't give language specifics.

Share this post


Link to post
Share on other sites
Thanks for the information!

Basicly, im trying to figure out what the best way to create things and be able to access and modify them.

For example:

Lets say I have a torch, a chair and an apple and i want to set atributes to each of them.

is it better to set each item as a class and create a new object for each time one is invoked?

Share this post


Link to post
Share on other sites
Quote:
Original post by navilon
Thanks for the information!

Basicly, im trying to figure out what the best way to create things and be able to access and modify them.

For example:

Lets say I have a torch, a chair and an apple and i want to set atributes to each of them.

is it better to set each item as a class and create a new object for each time one is invoked?


This would really be a lot like a MUD wouldnt it? So you might want to search for some tutorials on how MUD's interact with the environment, might give you some idea's.

Share this post


Link to post
Share on other sites
Hey,

If you are thinking about how to structure your code, I would recommend that you have a look at the text game creation tool called Inform. Inform uses a very sensible approach to handling ingame things in an object oriented way. It might be a good source of inspiration even if you don't want to use the actual Inform language. Nothing wrong with writing in Inform, but sounded like you want to work in C#.

Share this post


Link to post
Share on other sites
we actually have to write a text adventure for an assignment. we are given a small api, and its pretty extendable. you can take a look at how things are structured here, seems like a pretty good way for a basic engine.

http://courses.cs.vt.edu/~cs1705/api/

and go to cs1705.adventure

Share this post


Link to post
Share on other sites
If I were you, I'd have a single class for all items in your game. Each item can be an object of that class and the class would store all the information you need about the object such as the name, description, whether it can be taken and stuff like that.

Share this post


Link to post
Share on other sites
I'd also have a single class GameObject which posesses a dictionary for the properties. Naturally, you'd have a standard propertyset (Name, Description, etc) that would be part of the main class, but any other attributes that are likely to differ across the different objects would be well stored in a custom Dictionary (just wrap the DictionaryObject and add GetValue/SetValue code). This will allow you to refer to the extended properties by name:

GameObject chair = new GameObject("Wooden Chair");

chair.Properties.SetValue("weight", 100);

Console.WriteLine("The " + chair.Name + " has a weight of " + chair.Properties.GetValue("weight") );


With this method, you could quite easily serialise the object instances to a media set for loading/saving/exchange as it's a simple case of iterating the propertyset and reading/writing into it.

You can also create some helper functions to set up an object, for example if you know you'll be creating 100 chairs, it makes sesne to write a "CreateChair" method to set up all the default property values for the object.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!