from Hacker News

How to program a text adventure in C (2016)

by phodo on 3/22/20, 4:19 AM with 35 comments

  • by bserfaty on 3/22/20, 10:50 AM

    I suggest to look into https://ifcomp.org/ - the annual interactive fiction competition is running for 25 years now and there are some great games and resources over there.
  • by franze on 3/22/20, 10:11 AM

    Ask HN: what's a good JS (browser focused) text adventure engine? I see me making a text adventure (adding one mini chapter) each day as a good lockdown project.

    Note: I might call it "Everything is better in quarantine." The goal would be to (not) go mad.

  • by japanoise on 3/22/20, 7:57 AM

    I like this, very creative!

    The code generation looks interesting. I'll have to take another look later; can it not be done with the preprocessor?

  • by hendrikhalkow on 3/22/20, 1:07 PM

    Awesome work. Thanks. Looking forward to see more of those vintage games again :)
  • by hereisdx on 3/23/20, 4:36 AM

    Wow! This tutorial was very fun to follow.
  • by disqard on 3/22/20, 11:29 AM

    Thank you for writing this up!
  • by gustavorg on 3/22/20, 11:45 AM

    This programmer, Mr. Ruud Helderman, is like Cool McCool, "Danger is my business!". For example, the parser, function matchParam:

      OBJECT *obj;
      par->tag = src;
      par->distance = *src == '\0' ? distNoObjectSpecified : distUnknownObject;
      forEachObject(obj)
        ... 
    
    The initialization of the obj variable received an obliviate spell.

    Also function parseAndExecute (). The way he deal with invalid input is, epic:

      static const COMMAND commands[] =
      {
          {executeQuit      , "quit"},
          {executeLookAround, "look"},
          ...
      }
      for (cmd = commands; !matchCommand(input, cmd->pattern); cmd++);
      return (*cmd->function)();
  • by anthk on 3/22/20, 1:19 PM

    It's ok, but inform 6 is better for this.