Mazes are a traditional element of interactive fiction, often consisting of apparently identical rooms with exits that do not work reciprocally and which cause confusion.
The methods of mapping mazes are now fairly well understood and mazes themselves tend to be regarded as tiresome rather than enjoyable by a large portion of the playing audience. However, if we did want to ignore the common wisdom and create a maze, randomly generated at the start of play, here would be one way to go about it:
"Maze of Gloom"
A Bee Chamber is a kind of room. The printed name of a Bee Chamber is usually "Hexagonal Room". The description of a Bee Chamber is usually "Waxy, translucent walls surround you on six sides; the floor and ceiling are made of the same material, gently uneven. There are exits in every direction, cut into the faces or the corners."
Bee1, Bee2, Bee3, Bee4, Bee5, Bee6, Bee7, Bee8, Bee9, and Bee10 are Bee Chambers.
When play begins:
now right hand status line is "[number of visited rooms]/[number of rooms]";
repeat with place running through Bee Chambers:
now a random Bee Chamber is mapped north of place;
now a random Bee Chamber is mapped northwest of place;
now a random Bee Chamber is mapped west of place;
now a random Bee Chamber is mapped southwest of place;
now a random Bee Chamber is mapped south of place;
now a random Bee Chamber is mapped southeast of place;
now a random Bee Chamber is mapped east of place;
now a random Bee Chamber is mapped northeast of place;
now a random Bee Chamber is mapped above place;
now a random Bee Chamber is mapped below place;
now a random Bee Chamber is mapped inside place;
now a random Bee Chamber is mapped outside place.
Test me with "in / out / up / down / n / ne / nw / e / w / sw / se / s".
Suppose we want a game in which each scenario starts with the characters wearing hats -- randomly passed out. We might be tempted to write our scenario like this:
"Hatless"
The Costumery is a room. Larry, Curly, and Moe are men in the Costumery. Janine is a woman in the Costumery.
Rule for writing a paragraph about a person (called the target) who wears a hat (called attire):
say "[The target] is here, looking stylish in [an attire]."
Rule for writing a paragraph about a hatless person (called the target):
say "[The target] mopes about, hatless."
A hat is a kind of thing. A hat is always wearable. Definition: a person is hatless if he is not the player and he does not wear a hat.
The indigo bowler, the polka-dotted fedora, the pink beret, and the scarlet cloche are hats.
When play begins:
now every hat is worn by a random hatless person.
And we might hope that this would choose a new hatless person for each hat, but we would be wrong. It will instead choose one hatless person and put all the hats on him -- and everyone else has to go bare-headed. That's clearly no good. Let's try again:
"Hatless 2"
The Costumery is a room. Larry, Curly, and Moe are men in the Costumery. Janine is a woman in the Costumery.
Rule for writing a paragraph about a person (called the target) who wears a hat (called attire):
say "[The target] is here, looking stylish in [an attire]."
Rule for writing a paragraph about a hatless person (called the target):
say "[The target] mopes about, hatless."
A hat is a kind of thing. A hat is always wearable. Definition: a person is hatless if he is not the player and he does not wear a hat.
The indigo bowler, the polka-dotted fedora, the pink beret, and the scarlet cloche are hats.
When play begins:
now every hatless person wears a random hat.
But this selects one random hat and assigns it to each hatless person in turn -- so it will only wind up being worn by the last of them (since Inform knows that only one person can wear a hat at a time).
In this case, we do have to expand out our loop so that the game makes an explicit distribution:
"Hatless 3"
The Costumery is a room. Larry, Curly, and Moe are men in the Costumery. Janine is a woman in the Costumery.
Rule for writing a paragraph about a person (called the target) who wears a hat (called attire):
say "[The target] is here, looking stylish in [an attire]."
Rule for writing a paragraph about a hatless person (called the target):
say "[The target] mopes about, hatless."
A hat is a kind of thing. A hat is always wearable. Definition: a person is hatless if he is not the player and he does not wear a hat.
The indigo bowler, the polka-dotted fedora, the pink beret, and the scarlet cloche are hats.
When play begins:
repeat with item running through hats:
now the item is worn by a random hatless person.
Each time Inform considers the instruction "now the item is worn by a random hatless person", there is one fewer such person to choose from -- so we can guarantee that the hats are distributed one per customer and that all hats are distributed.
Hatless 3 is only guaranteed to work because the number of hats is less than or equal to the number of people; otherwise the final use of random will return "nothing" and then a problem message will appear during play.
"Technological Terror"
The Decomposition Ray Gun is a thing carried by the player.
First we need to define our shooting action:
Shooting it with is an action applying to two things.
Check shooting something with something:
if the player is not carrying the Ray Gun, say "You are pathetically unarmed!" instead;
if the second noun is not the Ray Gun, say "[The second noun] does not fire." instead;
if the noun is the Ray Gun, say "Nice trick if you can do it!" instead;
if the noun is the player, say "That would be disastrous!" instead.
Next, some grammar to allow the player to use this action:
Understand "shoot [gun] at [something ungunlike]" as shooting it with (with nouns reversed).
Definition: a thing is ungunlike if it is not the gun.
Understand "shoot [something ungunlike] with [gun]" as shooting it with. Understand "shoot [something] with [something]" as shooting it with.
Understand "shoot [something] at [something]" as shooting it with (with nouns reversed). Understand "fire [gun] at [something ungunlike]" as shooting it with (with nouns reversed). Understand "fire at [something ungunlike] with [gun]" as shooting it with. Understand "fire at [something] with [something]" as shooting it with.
Strictly speaking, we only need these last grammar lines (with "understand shoot something...") in order to define an action that the player can take. Adding more grammar lines means that Inform will try to match the most specific ones first, which is useful when the player types something ambiguous and there is one choice that obviously fits this action better than the others. See the chapter on Understanding for a further discussion.
Here we get to use "now..." to give it its destructive effect:
Carry out shooting something with something:
say "ZAP! [The noun] twinkles out of existence! [if something is part of the noun][The list of things which are part of the noun] clatter to the ground! [end if][paragraph break]";
now every thing which is part of the noun is in the location;
now the noun is nowhere.
The Deathbot Assembly Line is a room. "Here is the heart of the whole operation, where your opponents are assembled fresh from scrap metal and bits of old car." The dangerous robot is a thing in the Assembly Line. "One dangerous robot looks ready to take you on!" A robotic head, a drill arm, a needle arm, a crushing leg and a kicking leg are parts of the dangerous robot.
Instead of examining something when something is part of the noun:
say "[The noun] consists of [a list of things which are part of the noun]."
Test me with "x robot / shoot robot / fire at kicking leg / shoot gun at drill arm / look".