Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to store area data for a text adventure?

Tags:

c#

.net

I'm developing a "Zork" style text adventure in C#, and it's going to have a fairly large number of different areas with descriptions and environmental modifiers. I don't want to have a database, ideally, unless it really is the best way of doing it.

I need advice on the best way to store/load this data.

It will include:

  • Area description
  • Environmental modifiers (windows open/broken, door closed)
  • Items present by default
like image 484
Liggi Avatar asked Sep 17 '10 10:09

Liggi


4 Answers

I would solve your problem by abandoning C# and writing your program in Inform7. Inform7 is just about the most awesome programming language I have ever seen and it is specifically designed to solve your problem.

The awesome thing about Inform7 is that you write your text adventure in a language that resembles text adventures. For example, here's a fragment of one of the sample adventures' source code:

The iron-barred gate is a door. 
"An iron-barred gate leads [gate direction]." 
It is north of the Drawbridge and south of the Entrance Hall. 
It is closed and openable. 
Before entering the castle, try entering the gate instead. 
Before going inside in the Drawbridge, try going north instead. 
Understand "door" as the gate.

This adds an object to the game - the object is a door, it is called "the iron-barred gate". A door is understood to be between two rooms, in this case, the drawbridge and the entrance hall. If the player tries to "enter the drawbridge" then the game logic will know that this is the same as "go north", and then the door logic will determine whether the door is closed or not. And so on. It makes writing text adventures extremely easy.

Is there some particular reason why you want to use C# instead of a domain-specific language like Inform7? If your goal is to learn how to write C# code or how to build a parser or whatever, then by all means do it yourself. If your goal is to write a text adventure, then I'd use a language designed for that.

like image 154
Eric Lippert Avatar answered Sep 28 '22 06:09

Eric Lippert


Serialize all the data to file. It will ensure the smallest footprint when the user installs the game, without any real disadvantage. A database is great when you have a lot of data, but you are talking about a text adventure in which you will load the entire game contents into memory. A simple file will work for this very nicely.

Note, I'm not talking about xml but binary serialization. Any kind of text serialization will allow users to peek at your data, and either cheat or hack up the game. And you can just as easily swap in/out the serialized data file whether it's text or binary. Remember, your whole 'text' is likely to be just a few hundred kilobytes at most.

like image 27
Kirk Broadhurst Avatar answered Sep 28 '22 08:09

Kirk Broadhurst


There are many interactive fiction engines already. I would take a look at their data formats, that way you can re-use existing content and tools for editing the content.

The most popular engines currently are Glulx http://eblong.com/zarf/glulx/ and Z-Machine http://en.wikipedia.org/wiki/Z-machine

Here is a technical reference for the Glulx format: http://eblong.com/zarf/glulx/technical.txt

like image 22
Bryan Legend Avatar answered Sep 28 '22 06:09

Bryan Legend


I know you didn't want a DB, but have you looked at SQL Server Compact Edition? It might just do what you want.

like image 41
spender Avatar answered Sep 28 '22 06:09

spender