This creates a room with 6 doors, any of which can be opened, but once you've opened one, all the rest lock themselves.
! Rooms are illuminated by default in this game class room has light; ! Define a door which knows about the others, locks them all when it is opened, ! and then makes sure itself remains unlocked class hexdoor has static door openable lockable scenery with after [ x; open: objectloop (x ofclass hexdoor) give x locked; give self ~locked; ]; ! Define the room where the doors are, modifying the "exit" and "out" actions ! to automatically use whichever door is open room round_room "Round room" with description [ x; if (self has visited) { print "There are six doors of various colours spaced evenly around the walls."; objectloop (x ofclass hexdoor) if (x has open) "^The ",(name) x," stands open."; } else print "^You find yourself in a medium-sized room with six doors of various colours evenly spaced around the walls."; ], out_to [ x; objectloop (x ofclass hexdoor) if (x has open) return x; "You'll need to open a door first"; ], n_to black_door, s_to white_door, ne_to yellow_door, se_to green_door, nw_to blue_door, sw_to red_door; ! Each door is then defined as: hexdoor blue_door "blue door" round_room with description "The door is painted a pleasant shade of deep blue.", door_to blue_land, door_dir nw_to, with_key blue_key, name "blue" "door";
It would be nice to be able to say close door to close the only currently open door, instead of being asked which door you mean (after all, there's only one possibility, so why bother to ask?).
It turns out this is amazingly simple (although it's one of those programming things which took me many hours and several dead-ends to work out how to do it).
[ openhexdoor; if (noun ofclass hexdoor && noun in location && noun has open) rtrue; rfalse; ]; extend "close" first * noun=openhexdoor -> close;
I'm pretty sure I can work this up to a more general facility for closing any door which happens to be nearby (not just these special hexdoors), in the presence of other already-closed doors (Inform will already automatically close the only door in the vicinity without asking pointless questions, but it doesn't have the concept of which one of several might be open).
I'll wait until I've created another location with more than one door, and more than one of which can be simultaneously open, before trying this out. (The game is at a very early stage so far; I've spent most of my time doing this technical stuff in order to make further programming more straightforward.)
Go up
Return to main index.