Text-based game in C#

Posted on 2005-04-30
Last Modified: 2013-11-12
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 are games like this organized in code?  How to write an effective parser, etc.


Question by:knowlton
    1 Comment
    LVL 17

    Accepted Solution

    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.


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    For those of you searching for a fun but also medium paced MMORPG game I would highly suggest Ragnarok Online. This MMORPG is a bit older than World of Warcraft and in a way is extremely different. Compared to WoW's 3D environment and massive wor…
    Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now