Sunday, July 7, 2019

c# - Organising levels / rooms in a MUD-style text based world


I'm thinking of writing a small text-based adventure game, but I'm not particularly sure how I should design the world from a technical standpoint.


My first thought is to do it in XML, designed something like the following. Apologies for the huge pile of XML, but I felt it important to fully explain what I'm doing.





Kitchen





Kitchen
A small kitchen that looks like it hasn't been used in a while. It has a table in the middle, and there are some cupboards. There is a door to the north, which leads to the garden.


Cupboards
Knife

Batteries



Garden
The garden is wild and full of prickly bushes. To the north there is a path, which leads into the trees. To the south there is a house.





Woods
The woods are quite dark, with little light bleeding in from the garden. It is eerily quiet.

Trees01






door
N
Kitchen
Garden



path
N
Garden
Woods




0





Trees01
Trees



EXAMINE

The trees are tall and thick. There aren't any low branches, so it'd be difficult to climb them.




Cupboards
Cupboards






cupboard_open

EXAMINE

The cupboard is closed.
The cupboard contains some batteires.




cupboard_open

OPEN
The cupboard is already open.
You open the cupboard. It contains some batteries.


cupboard_open





cupboard_open

CLOSE
The cupboard is already closed.
You closed the cupboard./message>

cupboard_open






Batteries
Batteries

1




cupboard_open

GET

You picked up the batteries.







Obviously there'd need to be more to it than this. Interaction with people and enemies as well as death and completion are necessary additions. Since the XML is quite difficult to work with, I'd probably create some sort of world editor.


I'd like to know if this method has any downfalls, and if there's a "better" or more standard way of doing it.



Answer



If you're not completely wedded to C#, then the "more standard" way of doing this is to use one of the many text adventure creation tools which already exist to help people make exactly this kind of game. These tools give you an already-functioning parser, handling for death, save/restore/undo, character interaction, and other similar standard bits of text adventure functionality. Right now, the most popular authoring systems are Inform, and TADS (though there are a half dozen others available as well)


Inform can compile down into most of the Z Machine virtual machine instruction sets used by Infocom games, or into the more recent glulx virtual machine instruction sets. TADS, on the other hand, compiles down into its own virtual machine code.


Either type of binary can be run by most modern interactive fiction interpreters (in the old days, you often needed separate interpreters for TADS games from ZMachine games from glulx games. But thankfully, those days are basically over now.) Interpreters are available for just about any platform you'd want; Mac/PC/Linux/BSD/iOS/Android/Kindle/browser/etc. So you've already got cross-platform well and truly taken care of.


For most platforms, the currently-recommended interpreter is Gargoyle, but there are plenty of others, so do feel free to experiment.



Coding in Inform (especially the latest version) takes a little bit to get used to, since it's marketing itself more toward authors than toward engineers, and so its syntax looks weird and almost conversational. In Inform 7's syntax, your example would look like this:


"My Game" by Polynomial

Kitchen is a room. "A small kitchen that looks like it hasn't been used in a
while. It has a table in the middle, and there are some cupboards. There is a
door to the north, which leads to the garden."

In the Kitchen is a knife and some cupboards. The cupboards are fixed in
place and closed and openable. In the cupboards are some batteries.


Garden is north of Kitchen. "The garden is wild and full of prickly bushes.
To the north there is a path, which leads into the trees. To the south there
is a house."

Woods is north of Garden. "The woods are quite dark, with little light bleeding
in from the garden. It is eerily quiet."

Trees are scenery in the Woods. "The trees are tall and thick. There aren't any
low branches, so it'd be difficult to climb them."


Whereas TADS looks more like a traditional programming language, and the same game in TADS looks like this:


#charset "us-ascii"
#include
gameMain: GameMainDef
initialPlayerChar = me
;
versionInfo: GameID
name = 'My Game'
byline = 'by Polynomial'
;

startroom: Room /* we could call this anything we liked */
roomName = 'Kitchen' /* the displayed "name" of the room */
desc = "A small kitchen that looks like it hasn't been used
in a while. It has a table in the middle, and there
are some cupboards. There is a door to the north,
which leads to the garden."
north = garden /* where 'north' will take us */
;

+me: Actor

;

cupboards: OpenableContainer
vocabWords = 'cupboard/cupboards'
name = 'cupboards'
isPlural = true
location = startroom
;
battery: Thing
name = 'battery'

location = cupboards
;
knife: Thing
name = 'knife'
location = startroom
;
garden: Room
roomName = 'Garden'
desc = "The garden is wild and full of prickly bushes. To the
north there is a path, which leads into the trees. To

the south there is a house."
north = woods
south = startroom
;
woods: Room
roomName = 'Woods'
desc = "The woods are quite dark, with little light bleeding
in from the garden. It is eerily quiet."
south = garden
;

trees: Decoration
desc = "The trees are tall and thick. There aren't any low
branches, so it'd be difficult to climb them."
location = woods
;

Both systems are freely available, very frequently used, and have copious amounts of tutorial documentation (available from the links I gave above), so it's worth checking out both of them and picking the one you prefer.


Note that the two systems do have subtly different standard behaviours (although both may be modified). Here's a screenshot of the game being played, as compiled from the Inform source:


Inform screenshot


And here's one from the game being played (inside a terminal – typography can be a lot nicer than this), as compiled from the Tads source:



TADS3 screenshot


Interesting points to note: TADS gives you a 'score' display in the top right by default (but you can turn it off), while Inform doesn't (but you can turn it on). Inform will by default tell you open/closed states of items in the room description, Tads won't. Tads tends to automatically take actions for you in order to carry out player commands (unless you tell it not to), where Inform tends not to (unless you tell it to).


Either one can be used to make any sort of game (as they're both highly configurable), but Inform is more structured toward producing modern-style interactive fiction (often with minimal puzzles and more narrative in style), where TADS is more structured toward producing old-style text adventures (often strongly focused on puzzles and rigorously defining the mechanics of the game's world model).


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...