• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1231
  • Last Modified:

Text-based game in C#

I need a free online tutorial that shows how to write a text-based game like Zork.

It would be a DOS console application.  You would type "go north" or "look around" or "pick up sword" and the game world would update.

I am mostly interested in the engine...how are games like this organized in code?  How to write an effective parser, etc.


Thanks,

Tom
0
Tom Knowlton
Asked:
Tom Knowlton
1 Solution
 
davebytesCommented:
raw zork style games didn't need a real 'complex' parser, just a tokenizer and simpler rules.  everything is a command, with spaces separating the words.  The words are in specific places in the command 'parse' order (action/verb and object for the basics).  Generally, the early games used VERY strict parser order.

First, drop all articles, as they're generally useless.  I've left them in below just for location.  Then, basic construction is something like:

(((verb [prep]) {art} noun) [(prep {art} noun)])

first key token is verb.

in some cases, it's a verb-prep clause ("pick up") that needs a noun, in some cases it's a verb-prep command (look around).

next token is the key noun, if one.  (grab "sword")

next token is a secondary preposition, for instructing the command (put key "in" hole).  most of the game parsers were just fine without the secondary preposition, meaning they looked for verb-prep or verb-noun-noun as raw command structure...

last token is secondary noun.  (put key in "hole").

Note they also had particular quoted commands like: say "xyzzy", sometimes quoted, more likely just identified as special fake 'nouns'.  depends on the complexity of interaction.

Effective organization?  Depends on how complex.  You can build a complex expression parser using lexx/yacc with the entire grammar for the game, and let it do the heavy lifting.  If you are trying to LEARN from the experience, I generally would look at a finite-state-machine parser that steps forward through the set of tokens trying to build a 'full' command.  Using tables for each possible 'state', you can quickly build up your language set.

-d
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now