How to Create the Sword from Zork
While most kids were growing up playing video games, I spent hours discovering new worlds and solving puzzles in text adventures.
My favorite, and one I never figured out how to finish, was Zork. Zork was one of the earliest text adventures and it become popular as personal computers were gaining prominence.

Game players were thrust into a mysterious world where they had to solve puzzles, find treasures, and not die.
The entirety of Zork was split into three parts, but one constant between the three sections was the Elvish Sword. At the start of each game, the player would have the sword on them or find it nearby.
Not only was the sword effective for fighting monsters encountered along the journey, but it warned of nearby enemies by glowing a blue color.
After spending so much time using this sword in Zork, I was interested in learning how to create it in Inform.
If you’re not familiar with Inform, a programming language meant for programming text adventures, check out my tutorial on the language!
If you’re already familiar with Inform (or can read English sentences — because that’s basically what it is), here’s how to create your own Elvish Sword!
1. Set up rooms for your player to move around in.
First, we will set up the map that we will have our player explore. My map is going to look like this:

Instead of writing out a description for each room I want to create, I’m going to define a kind of room called Ordinary Room and set its usual description. Then, I will create nine rooms of type Ordinary Room that all use the usual description.
A Ordinary Room is a kind of room. The description of an Ordinary Room is usually “It looks like an ordinary room. There are exits in several directions.”Northwest Room, North Room, Northeast Room, East Room, West Room, Southwest Room, South Room, Southeast Room, and Middle Room are Ordinary Rooms.
Then, we will set up directions from room to room, replicating the links in our map above.
Northwest Room is northwest of Middle Room.
Northwest Room is west of North Room.
Northwest Room is north of West Room.
North Room is north of Middle Room.
Northeast Room is northeast of Middle Room.
Northeast Room is east of North Room.
Northeast Room is north of East Room.
West Room is west of Middle Room.
East Room is east of Middle Room.
Southwest Room is southwest of Middle Room.
Southwest Room is south of West Room.
Southwest Room is west of South Room.
South Room is south of Middle Room.
Southeast Room is southeast of Middle Room.
Southeast Room is east of South Room.
Southeast Room is south of East Room.By default, our character will start in the first room we create. In this case, our player will start in the the northwest corner of our map.
2. Create the sword.
This step is pretty simple. All we have to do is create an object called “Elvish Sword” and put it in the room that our player will start in.
An Elvish Sword is in the Northwest Room.3. Create an enemy.
In the classic Zork fashion, my enemy will be a troll. We’re going to define a troll as a type of person and give our troll a name. Using a troll name generator, I’ve decided to name my troll Ekon.
A troll is a kind of person. Ekon is a troll.Now that we have an existing troll, we need to place him in our map. Since our magical sword would be a little less magical if we already knew where our enemy was, I’m going to randomly place Ekon in a room when the game starts.
When play begins:
move Ekon to random room;So, now, when the game begins, we’ll end up with something like the following, where the sword and player are in the northwest corner and the troll is in a random room.

4. Create the conditions that the sword will glow.
In the Zork world, the sword glows faintly when an enemy is near, and brightly when the player is in the same room as an enemy. Inform makes it easy to encode this logic:
Every turn:
if the player is carrying the Elvish Sword and going to any room:
if Ekon is visible, say “Your sword has begun to glow very
brightly.”;
if Ekon is in an adjacent room, say “Your sword is glowing with
a faint blue glow.”;Every turn we’re going to check if the player is carrying the sword and is also going to a new room. If so, we will check to see if that room is near Ekon and print an appropriate message about the sword glowing.
5. Set an end condition for the game
No game is complete without an ending! I decided to end the game when the player attacks Ekon:
Instead of attacking Ekon:
if the player is carrying the Elvish sword, end the story.And that’s it! Inform makes it easy to create people and objects and create relationships between them.
Typical gameplay might look something like this:

If you want to see this code in action, you can try out this project here.
Full Code:
“The Elvish Sword” by Julianna Stevenson[ Room setup ]A Ordinary Room is a kind of room. The description of an Ordinary Room is usually “It looks like an ordinary room. There are exits in several directions.”Northwest Room, North Room, Northeast Room, East Room, West Room, Southwest Room, South Room, Southeast Room, and Middle Room are Ordinary Rooms.[ Place rooms ]Northwest Room is northwest of Middle Room.
Northwest Room is west of North Room.
Northwest Room is north of West Room.
North Room is north of Middle Room.
Northeast Room is northeast of Middle Room.
Northeast Room is east of North Room.
Northeast Room is north of East Room.
West Room is west of Middle Room.
East Room is east of Middle Room.
Southwest Room is southwest of Middle Room.
Southwest Room is south of West Room.
Southwest Room is west of South Room.
South Room is south of Middle Room.
Southeast Room is southeast of Middle Room.
Southeast Room is east of South Room.
Southeast Room is south of East Room.[ Object setup ]An Elvish Sword is in the Northwest Room.A troll is a kind of person. Ekon is a troll.[ Logic ]Instead of attacking Ekon:
if the player is carrying the Elvish sword, end the story.
When play begins:
move Ekon to random room;Every turn:
if the player is carrying the Elvish Sword and going to any room:
if Ekon is visible, say “Your sword has begun to glow very
brightly.”;
if Ekon is in an adjacent room, say “Your sword is glowing with
a faint blue glow.”;
