Get Started:Create a Puzzle
We've got a locked door and we've got a key. The key is just laying on the ground where anyone can pick it up. Recalling that our dungeon is made of cobblestones, let's make a fake cobblestone to hide the key in. We haven't got a pre-defined class for a cobblestone, but we can make one out of the Thing class.
MyGame.createAsset({
class: "Thing",
name: "pitted cobblestone",
aspects: { in: { with_assets: [ "pitted iron key" ], }, },
dov: { open: { with_nothing: true }, close: { with_nothing: true } },
is: { closed: true },
description: "It's an especially pitted cobblestone. ",
article: "a",
adjectives: [ ],
place: { in: "Dungeon Antechamber" },
});
And then we'll revise the Key slightly to put it inside the cobblestone.
MyGame.createAsset({
class: "Key",
name: "beaten iron key",
iov: { unlock: { with_assets: ['wood planked door'], }, },
description: "It's a thick, heavy key made of beaten iron. ",
article: "a",
adjectives: [ ],
place: { in: "pitted cobblestone" },
});
// game constructor block...
// player constructor block...
// dungeon antechamber constructor block...
// north exit constructor block...
// wood planked door constructor block...
// central chamber constructor block...
// south exit constructor block...
// iron bound door constructor block...
// beaten iron key constructor block...
// pitted cobblestone constructor block...
And now we have... well, just a cobblestone sitting on the floor instead of a key, which is still a bit too obvious. We can do better. But before we move on, here are a couple of things to note about our cobblestone.
- Instances of Thing are already subscribed to a number of verbs out of the box, but here we've added open and close. We've set dov: { open: { with_nothing: true } so that the cobblestone can be opened without the aid of any indirect object.
- We've set aspects: { in: { with_assets: [ "pitted iron key" ], }, }, to give the cobblestone an aspect that can only hold the key.
Here's our revised strategy. Since the room description mentions cobblestones, we're going to make our cobblestone blend in to the room. First, we're going to set is:{ listed_in_room: false }, which prevents items from being listed in room descriptions. The downside of not listing things is that unlisted things are not automatically made known to the player. So we'll manually make the cobblestone known by setting is: { known: true }. Then, we'll spruce up the description a little bit and give it some simple logic to let the player know whether it's open or closed.
MyGame.createAsset({
class: "Thing",
name: "pitted cobblestone",
aspects: { in: { with_assets: [ "pitted iron key" ], }, },
dov: { open: { with_nothing: true }, close: { with_nothing: true } },
is: { closed: true, known: true, listed_in_room: false },
description: "The surface of this cobblestone seems especially pitted. The stone appears to be seamed, suggesting that it must be hinged. Currently it is $( pitted cobblestone is| open or| closed ). ",
article: "a",
adjectives: [ ],
place: { in: "Dungeon Antechamber" },
});
#TMI $( pitted cobblestone is| open or| closed )
You might have noticed where we used $( pitted cobblestone is| open or| closed ). That is a slightly advanced technique we call a custom template. It looks very similar to a Javascript template literal, and it serves a similar purpose, but it's not the same thing. Template literals use ${braces}, whereas Adventurejs custom templates use $(parens). In fact, you can use both in any code that is destined to be printed to the display. We'll cover this in depth in a later tutorial.
Next, we're going to make a couple more cobblestones, to flesh things out a bit and give the user some choices (also known as: the illusion of free will).
MyGame.createAsset({
class: "Thing",
name: "weathered cobblestone",
is: { listed_in_room: false, known: true },
description: "This cobblestone looks particularly weathered. Which is odd, given that it's underground where there's no weather to speak of. ",
article: "a",
adjectives: [ ],
place: { in: "Dungeon Antechamber" },
});
MyGame.createAsset({
class: "Thing",
name: "cracked cobblestone",
is: { listed_in_room: false, known: true },
description: "This cobblestone is splintered with a spider's web of fine cracks. ",
article: "a",
adjectives: [ ],
place: { in: "Dungeon Antechamber" },
});
Then, we're going to make a cobblestones collection. The Collection class is a special class that allows a player to refer to a group of things. In this case, we want it so the player can say "examine cobblestones" without getting a dumb answer.
MyGame.createAsset({
class: "Collection",
name: "cobblestones",
place: { in: "Dungeon Antechamber" },
collection: "pitted cobblestone, weathered cobblestone, cracked cobblestone",
synonyms: [ ],
is: { listed_in_room: false, known: true },
description: "The entire room seems to be laid in cobblestones. Not just the floor, but also the walls and ceiling. The stones around the frame of the wood planked door draw your eye. Three in particular stand out: a cracked cobblestone, a weathered cobblestone, and a pitted cobblestone. ",
});
Finally, we're going to tweak the room's description to make the cobblestones stand out, so that they're more likely to catch the player's attention.
MyGame.createAsset({
class: "Room",
name: "Dungeon Antechamber",
description: "You're in a dingy dungeon antechamber. The air here is dank and oppressive, leavened only by a slight draft of fresh air at your back. A dark path descending to the north is bound by a massive wood planked door. Every surface of the dungeon seems to be made of pitted cobblestones. The cobblestones around the door frame appear to be particularly irregular. ",
exits:
{
south: "You feel the lure of the tiny patch of sky that's still visible through the entrance... but you don't want to leave without the treasure! ",
},
});
Try it now! Try "x cobblestones"
// game constructor block...
// player constructor block...
// dungeon antechamber constructor block...
// north exit constructor block...
// wood planked door constructor block...
// central chamber constructor block...
// south exit constructor block...
// iron bound door constructor block...
// beaten iron key constructor block...
// pitted cobblestone constructor block...
// weathered cobblestone constructor block...
// cracked cobblestone constructor block...
// cobblestones constructor block...
All the pieces have come together. The only thing we're missing now is some treasure!