// new functionality that would've made this easier/better: // functions to avoid typing duplicate code // actions over subsets of the commands set // counters // a way to specify default actions upon entry/exit of a room // allow premature exits from actions // some method to handle creating only one action structure for a command, letting room-specific ones dominate commands = {i,n,s,e,w,put,wear,drop,look,read} room you { } room Foyer { (you,look) { "You are in an empty Foyer. To the north is a blocked door."; if (Bar.lit) { "Light streams from a doorway to the south."; } else { "To the south is a dark doorway."; } "To the west is a small cloakroom."; } (you,n) { "The way north is blocked."; } (you,s) { if (Bar.lit) { "You walk into a brightly lit bar."; } else { "You walk into the darkness."; } move you from Foyer to Bar; } (you,w) { move you from Foyer to Cloakroom; "You walk into a small cloakroom."; } (you,e) { "You can't go that way."; } (you,put) { "Put the cloak where?"; } (you,drop) { "On the dirty foyer floor? Never!"; } (you,wear) { "Wear what?"; } } room Bar { state {lit,dark0,dark1,dark2} (you,look) { if (Bar.lit) { "You're in a brightly lit bar. It clearly hasn't been used in a long time."; "There's a message scrawled in the dust on the floor."; } else { if (Bar.dark0) { -Bar.dark0; +Bar.dark1; } elseif (Bar.dark1) { -Bar.dark1; +Bar.dark2; } "You stumble around a bit, but can't see anything."; } } (you,read) { if (Bar.lit) { if (Bar.dark0) { "The message says: 'You have won.'"; +game.win; } elseif(Bar.dark1) { "It's a bit hard to read, but it says: 'You have won.'"; +game.win; } elseif(Bar.dark2) { "The dust is too disturbed to make it out...."; "...oh, wait, there it is: 'You have lost.'"; +game.lose; } } if (Bar.dark0) { -Bar.dark0; +Bar.dark1; } elseif (Bar.dark1) { -Bar.dark1; +Bar.dark2; } "You grope around in the dark, but can't see anything to read."; } (you,n) { move you from Bar to Foyer; "You step back into the Foyer."; } (you,s) { if (Bar.lit) { "You can't go that way."; } else { if (Bar.dark0) { -Bar.dark0; +Bar.dark1; } elseif (Bar.dark1) { -Bar.dark1; +Bar.dark2; } "You shuffle forward a little, but it's dangerous to move in the dark."; } } (you,e) { "You can't go that way."; } (you,w) { "You can't go that way."; } (you,put) { "Put the cloak where?"; } (you,drop) { "On the dusty floor? Never!"; } (you,wear) { "Wear what?"; } } room Cloakroom { (you,look) { "You're in a small cloakroom. The only exit is the way you came in."; if (Cloak.floor) { "A cloak lies crumpled on the floor."; } elseif (Cloak.hook) { "A cloak hangs neatly on the cloak hook."; } elseif (Cloak.worn) { "A small brass cloak hook is fixed to the wall."; } } (you,e) { move you from Cloakroom to Foyer; "You step back into the Foyer."; } (you,w) { "You can't go that way."; } (you,s) { "You can't go that way."; } (you,n) { "You can't go that way."; } (you,read) { "Read what?"; } (you,drop) { if (Cloakroom contains you && Cloak.worn) { move Cloak from you to Cloakroom; -Cloak.worn; +Cloak.floor; +Bar.lit; "You drop the cloak on the floor."; } } (you,put) { if (Cloakroom contains you && Cloak.worn) { move Cloak from you to Cloakroom; -Cloak.worn; +Cloak.hook; +Bar.lit; "You hang the cloak on the cloak hook."; } } (you,wear) { if (Cloakroom contains you && Cloak!.worn) { move Cloak from Cloakroom to you; +Cloak.worn; -?Cloak.hook; -?Cloak.floor; -Bar.lit; "You put the cloak on."; } } } object Cloak { state {floor,hook,worn} } start { +Bar.dark0; move you from offscreen to Foyer; move Cloak from offscreen to you; +Cloak.worn; "You enter the Opera House and stand in an empty Foyer."; } (you,i) { if (Cloak.worn) { "You're wearing a black velvet cloak. It's so dark, light seems to be sucked into it."; } else { "You've got nothing."; } }