
How to program a text adventure in C (2016) - phodo
http://home.hccnet.nl/r.helderman/adventures/htpataic01.html
======
bserfaty
I suggest to look into [https://ifcomp.org/](https://ifcomp.org/) \- the
annual interactive fiction competition is running for 25 years now and there
are some great games and resources over there.

~~~
sn41
The greatest text games I have played are Curses! and Anchorhead. Both are
immersive and vast. Anchorhead is genuinely scary. There are some pointless
puzzles and timed puzzles, but overall, truly worth trying out.

~~~
nvarsj
Thanks for the suggestions! I've never heard of IF before - but I'm a long
time MUD / roguelike player. This looks really great.

~~~
tarboreus
I recommend Counterfeit Monkey, it's the top-rated game on IFDB and I think it
deserves that spot. It's also a game that would be impossible to create
graphically.

[https://ifdb.tads.org/viewgame?id=aearuuxv83plclpl](https://ifdb.tads.org/viewgame?id=aearuuxv83plclpl)

------
franze
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.

~~~
kd5bjo
The classic engine is Inform, and a quick look in the manual says it can
publish to a playable webpage: [http://inform7.com/](http://inform7.com/)

~~~
indigochill
Inform is definitely the leader in parser fiction and there's been some
amazing games made from it (Counterfeit Monkey and Hadean Lands being two of
my favorites).

I would throw Ink (from Inkle, creators of 80 Days, Steve Jackson's Sorcery!,
and Heaven's Vault) in the ring for the choice-driven variant of IF. It also
publishes a playable webpage. I made a sort of unconventional portfolio-like
page with it here: [https://maxsond.github.io/](https://maxsond.github.io/)

------
japanoise
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?

------
hendrikhalkow
Awesome work. Thanks. Looking forward to see more of those vintage games again
:)

------
hereisdx
Wow! This tutorial was very fun to follow.

------
disqard
Thank you for writing this up!

------
gustavorg
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)();

~~~
jstimpfle
This is C89 style code where you couldn't declare the loop variables in the
for loop, as in "for (OBJECT * obj = ... ". There's no problem with this code.
The _obj_ variable is initialized in the _forEachObject_ macro which expands
to a for loop. (Pretty damn sure - I haven't actually looked up the
definition).

The array iteration code is also solid. Seems like a pretty good programmer,
judging from the code you cite here at least.

While I personally like to put a few assertions just to find my typos quicker,
adding additional fluff here is mostly detrimental. The kind of bugs that can
happen with this sort of "dangerous" code are the ones that you basically just
typos that you catch on the first run. I.e. it's not like there are any rarely
occurring edge cases that are unhandled, since the code is extremely
straightforward. The "complexity" is very low.

~~~
kbumsik
> The array iteration code is also solid.

Shouldn't there be a NULL at the end of the array and do a null check in the
iteration?

~~~
pm215
I think the last array entry {executeNoMatch , "A?"} will match on any string
(and print the fallback "I don't know how to VERB" message), so it's
impossible to fall off the end of the array. If you wanted to use a more
defensive-programming style then you could add a sentinel of some kind and
assert that you never hit it.

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

~~~
alekq
It’s great that you read the linked page, because at the introduction he
wrote:

But then, why this tutorial? Why write an adventure game using a general-
purpose programming language? Because doing so can be entertaining,
challenging and educational. The programming language C may not be the most
obvious choice for writing a text adventure; it's nothing like LISP-based
languages like MDL and ZIL. But while writing my own humble text adventure, I
learned that C fits the bill quite well.

