Interactive Fiction_2 – Doors

PLAY EXAMPLE

Doors
Doors can be integral elements of IF and dealing with locked doors are standard puzzles. Creating doors in IF takes some extra work, thinking, and coding since they behave differently than other objects in Inform 7. Doors are unique in that they have two sides and connect two rooms. For now, think of a door in IF as another room that connects two other rooms.

Doors can also have the following properties:

they can be open (it is open to start),
they can be closed (it is closed to start – this is the default),
they can be locked (it is locked to start),
and they can be lockable (it is unlocked to start but can be locked).

Here is how we code a door in IF:

The iron gate is a door. It is east of the Sidewalk and west of the Front Porch.
.
A door is created by establishing its relationship between two existing rooms which by default also establishes its location.
 
Let’s create the two adjacent rooms to complete the map:
The iron gate is a door. It is east of the Sidewalk and west of the Front Porch.
The Sidewalk is a room. “This is the sidewalk in front of the house you grew up in. The front porch of your old house is to
the east.”
The Front Porch is a room. “The wooden boards of this porch creak under your weight. The sidewalk is to the west.”
 .
Note carefully what is going on here:
1. The rooms do not have the pathways included because the door object contains the pathway information.
2. The door object declares two pathways: the direction from the Sidewalk room to the door and the direction from the Front Porch room to the door.
 .
Here is how this would look (and behave) in play:
Sidewalk
This is the sidewalk in front of the house you grew up in.
The front porch of your old house is to the east.
You can see an iron gate here.
>go east
You can’t, since the iron gate is in the way.
>open iron gate
You open the iron gate.
>go east
Front Porch
The wooden boards of this porch creak under your weight. The sidewalk is to the west.
You can see an iron gate here.
 
Scenery
You should also have noticed that doors are mentioned separately from the room description. This is usually undesirable since the mention of the door provides no information as to which direction the door leads to. The solution to this is make the door scenery (so it will not be mentioned separately) and to mention the door in both of the room descriptions (so the player knows it is there.)
The iron gate is a door. It is scenery. It is east of the Sidewalk and west of the Front Porch.
The Sidewalk is a room. “This is the sidewalk in front of the house you grew up in. An iron gate to the east leads to the front porch of your old house.”
The Front Porch is a room. “The wooden boards of this porch creak under your weight. The sidewalk is to the west through an iron gate.”
 .
You should also provide a description for this iron gate in case the player wishes to examine it or should prove to provide a valuable clue in your work.
The iron gate is a door. It is scenery. It is east of the Sidewalk and west of the Front Porch.
The description is “The white enamel paint that once covered this old gate is almost gone exposing the rusting metal.”
 .
Note too that, by default, doors are initially closed and the player has to open the door the first time they wish to pass through. The door will then remain open until it is explicitly closed.
We could code the door so the player doesn’t have to open it:
The iron gate is an open door. It is east of the Sidewalk and west of the Front Porch.
But then what is the point of even having the door?
 .
LOCKED DOORS
The implication is that doors, in the majority of cases, can be more trouble than they are worth. Where doors do come in handy is in the creation of a locked passageway where finding the key that unlocks a door becomes a puzzle to be solved.
 
The following demonstrates how to create a locked door and the key that will unlock it.
Examine the following code carefully:
The Foyer is a room. “You can see a closet door to the east.”
The Closet is a room. “The closet is empty.”
The closet door is a locked door and scenery. It is east of the Foyer and west of the Closet. The silver key unlocks the closet door.
The silver key is carried by the player. The description is “Etched on the silver key is the word ‘closet’.”
 .
The two rooms and the connecting door are created as done previously but note the following additions:
• The first sentence declares that the closet door is locked (starts off in a locked state) door.
• The last sentence declares that an object called the silver key can unlock (and lock) the closet door. (This is similar to a locked container discusses previously.)
Then we create an object called the silver key that is initially carried by the player (in their inventory.)
Now when the player types “unlock closet door with silver key”, the closet door will be unlocked and then can be opened and closed. The closet door can also be locked by typing “lock closet door with silver key” should the player wish (or need) to.
 

____________________________________________________________________________________________________
ASSIGNMENT
After working through the above examples…

Using Inform 7 or www.playfic.com create a story that has a player:
     Go through a gate (which is scenery).
     Go through a locked front door.  

Copy and past your working code into notepad and hand in your code.

____________________________________________________________________________________________________


This resources is from –  http://www.hpiweb.com/newmedia/  
There are several good resources on this site.  In particular there are some really useful snippets of code.  Now a dead link.

 

Leave A Reply

Your email address will not be published. Required fields are marked *