! ============================================================================ !
!   Cloak of Darkness - a simple demonstration of Interactive Fiction
!       This version for Inform written by Roger Firth on 17Sep99
! ============================================================================ !

Constant Story      "Cloak of Darkness";
Constant Headline   "^A basic IF demonstration.^";
Constant MANUAL_PRONOUNS;
Constant MAX_SCORE  2;

Include "Parser";
Include "VerbLib";

! ============================================================================ !

Object  foyer "Foyer of the Opera House"
  with  description
           "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.",
        s_to  bar,
        w_to  cloakroom,
        n_to
           "You've only just arrived, and besides, the weather outside
            seems to be getting worse.",
  has   light;

Object  cloakroom "Cloakroom"
  with  description
           "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.",
        e_to  foyer,
  has   light;

Object  hook "small brass hook" cloakroom
  with  name 'small' 'brass' 'hook' 'peg',
        description [;
            print "It's just a small brass hook, ";
            if (self == parent(cloak)) "with a cloak hanging on it.";
            "screwed to the wall.";
            ],
  has   scenery supporter;

Object  bar "Foyer bar"
  with  description
           "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.",
        n_to  foyer,
        before [;
            Go:
                if (self hasnt light && noun ~= n_obj) {
                    message.number = message.number + 2;
                    "Blundering around in the dark isn't a good idea!";
                    }
            default:
                if (self hasnt light) {
                    message.number = message.number + 1;
                    "In the dark? You could easily disturb something!";
                    }
            ],
  has   ~light;

Object  cloak "velvet cloak"
  with  name 'handsome' 'dark' 'black' 'velvet' 'satin' 'cloak',
        description
           "A handsome cloak, of velvet trimmed with satin, and slightly
            spattered with raindrops. Its blackness is so deep that it
            almost seems to suck light from the room.",
        before [;
            Drop, PutOn:
                if (location == cloakroom) {
                    give bar light;
                    if (action == ##PutOn && self has general) {
                        give self ~general;
                        score++;
                        }
                    }
                else
                   "This isn't the best place to leave a smart cloak
                    lying around.";
            ],
        after [;
            Take: give bar ~light;
            ],
  has   clothing general;

Object  message "scrawled message" bar
  with  name 'message' 'sawdust' 'floor',
        description [;
            if (self.number < 2) {
                score++;
                deadflag = 2;
                print "The message, neatly marked in the sawdust, reads...";
                }
            else {
                deadflag = 3;
                print "The message has been carelessly trampled, making it
                  difficult to read. You can just distinguish the words...";
                }
            ],
        number  0,
  has   scenery;

[ Initialise;
    location = foyer;
    move cloak to player;
    give cloak worn;
   "^^Hurrying through the rainswept November night, you're glad to see the
    bright lights of the Opera House. It's surprising that there aren't more
    people about but, hey, what do you expect in a cheap demo game...?^^";
    ];

[ DeathMessage; print "You have lost"; ];

! ============================================================================ !

Include "Grammar";

Verb 'hang'     * held 'on' noun    -> PutOn;

! ============================================================================ !


And now for something completely different; this version for Inform 7 written by Emily Short and Graham Nelson in March 2007:

"Cloak of Darkness"

The story headline is "A basic IF demonstration."

The maximum score is 2.

[Whatever room we define first becomes the starting room of the game,
in the absence of other instructions:]

Foyer of the Opera House is a room.  "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."

Instead of going north in the Foyer, say "You've only just arrived, and besides,
the weather outside seems to be getting worse."

[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":]

The Cloakroom is west of the Foyer.
"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."

In the Cloakroom is a supporter called the small brass hook.
The hook is scenery. Understand "peg" as the hook.

[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.]

The description of the hook is "It's just a small brass hook,
[if something is on the hook]with [a list of things on the hook]
hanging on it[otherwise]screwed to the wall[end if]."

[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.]

The Bar is south of the Foyer. The printed name of the bar is "Foyer Bar".
The Bar is dark.  "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."

The scrawled message is scenery in the Bar. Understand "floor" or "sawdust" as the message.

Neatness is a kind of value. The neatnesses are neat, scuffed, and trampled.
The message has a neatness. The message is neat.

[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.]

Instead of examining the message:
    increase score by 1;
    say "The message, neatly marked in the sawdust, reads...";
    end the game in victory.

[This second rule takes precedence over the first one whenever the message is trampled.
Inform automatically applies whichever rule is most specific:]

Instead of examining the trampled message:
    say "The message has been carelessly trampled, making it difficult to read.
    You can just distinguish the words...";
    end the game saying "You have lost".

[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:]

Instead of doing something other than going in the bar when in darkness:
    if the message is not trampled, change the neatness of the message
    to the neatness after the neatness of the message;
    say "In the dark? You could easily disturb something."

Instead of going nowhere from the bar when in darkness:
    now the message is trampled;
    say "Blundering around in the dark isn't a good idea!"

[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.]

The player wears a velvet cloak. The cloak can be hung or unhung.
Understand "dark" or "black" or "satin" as the cloak.
The description of the cloak is "A handsome cloak,
of velvet trimmed with satin, and slightly splattered with raindrops.
Its blackness is so deep that it almost seems to suck light from the room."

Carry out taking the cloak:
    now the bar is dark.

Carry out putting the unhung cloak on something in the cloakroom:
    now the cloak is hung;
    increase score by 1.

Carry out putting the cloak on something in the cloakroom:
    now the bar is lit.

Carry out dropping the cloak in the cloakroom:
    now the bar is lit.

Instead of dropping or putting the cloak on when the player is not in the cloakroom:
    say "This isn't the best place to leave a smart cloak lying around."

When play begins:
    say "[paragraph break]Hurrying through the rainswept November night,
    you're glad to see the bright lights of the Opera House.
    It's surprising that there aren't more people about but, hey,
    what do you expect in a cheap demo game...?"

Understand "hang [something preferably held] on [something]" as putting it on.

Test me with "s / n / w / inventory / hang cloak on hook / e / s / read message".