Cloak of Darkness
"Cloak of Darkness" is a brief example game that has been implemented in nearly every IF system currently used. It hasn't got much claim to complexity or richness, but it does exemplify many of the standard things one might want an IF language to be able to do: define descriptions and the results of actions, assign synonyms to nouns, create new verbs, handle darkness, track repeated acts, and so on.
Here is what the game looks like in Inform:
Whatever room we define first becomes the starting room of the game, in the absence of other instructions:
We can add more rooms by specifying their relation to the first room. Unless we say otherwise, the connection will automatically be bidirectional, so "The Cloakroom is west of the Foyer" will also mean "The Foyer is east of the Cloakroom":
Inform will automatically understand any words in the object definition ("small", "brass", and "hook", in this case), but we can add extra synonyms with this sort of Understand command.
This description is general enough that, if we were to add other hangable items to the game, they would automatically be described correctly as well.
We could if we wished use a number to indicate how many times the player has stepped on the message, but Inform also makes it easy to add descriptive properties of this sort, so that the code remains readable even when the reader does not know what "the number of the message" might mean.
This second rule takes precedence over the first one whenever the message is trampled. Inform automatically applies whichever rule is most specific:
This command advances the state of the message from neat to scuffed and from scuffed to trampled. We can define any kinds of value we like and advance or decrease them in this way:
This defines an object which is worn at the start of play. Because we have said the player is wearing the item, Inform infers that it is clothing and can be taken off and put on again at will.
Test me with "s / n / w / inventory / hang cloak on hook / e / s / read message".
You are standing in a spacious hall, splendidly decorated in red and gold, with glittering chandeliers overhead. The entrance from the street is to the north, and there are doorways south and west.
>(Testing.)
>[1] s
Darkness
It is pitch dark, and you can't see a thing.
>[2] n
Foyer of the Opera House
You are standing in a spacious hall, splendidly decorated in red and gold, with glittering chandeliers overhead. The entrance from the street is to the north, and there are doorways south and west.
>[3] w
Cloakroom
The walls of this small room were clearly once lined with hooks, though now only one remains. The exit is a door to the east.
>[4] inventory
You are carrying:
a velvet cloak (being worn)
>[5] hang cloak on hook
(first taking it off)
You put the velvet cloak on the small brass hook.
[Your score has just gone up by one point.]
>[6] e
Foyer of the Opera House
You are standing in a spacious hall, splendidly decorated in red and gold, with glittering chandeliers overhead. The entrance from the street is to the north, and there are doorways south and west.
>[7] s
Foyer Bar
The bar, much rougher than you'd have guessed after the opulence of the foyer to the north, is completely empty. There seems to be some sort of message scrawled in the sawdust on the floor.
>[8] read message
The message, neatly marked in the sawdust, reads...
*** The End ***
In that game you scored 2 out of a possible 2, in 8 turns.
And that's all. As always, type TEST ME to watch the scenario play itself out.