Thursday, November 15, 2012

Cloak of Darkness

Since its invention by Roger Firth in 1999, Cloak of Darkness has functioned as a helpful blueprint of how to implement a simple game design across numerous languages -- the point of making new versions of CoD (and there are perhaps dozens) is not in the end result but in getting to peruse the source code and observe just how it was done in language (x). In May 2011, while on an airplane to Amsterdam, I came upon the idea of making a version in dog-dumb HTML for this very blog (in its first heat then) ... I took a page of notes and then set them aside two weeks later upon seeing that Juhana Leinonen had just implemented a very neat, beautiful version in Undum -- binding up the market for native browser-playable versions of this particular design, right? No way I can compete with that. But still, who will take one for the team and demonstate what would be involved in making an HTML version of the game? (Four versions of most rooms, it turns out, accounting for all combinations of two variables.) With a recently-renewed enthusiasm for finishing what I start... this guy. (A happy accident the "rainswept November night" rang so true!)

(My personal Cloak of Darkness, for "let's see how they do it" purposes in different CYOA languages, is A Story As You Like It -- but as you can see, despite dabbling with it in a few languages, the only version that's gone live yet is the one I launched right here.)

In any case, this demonstration will be of limited use, since Blogger will assuredly manhandle any HTML I feed into it -- but what results should still be adequately valid for its source code to be of use or interest to at least the most non-programmatic inquirer.

. . .

Cloak of Darkness - A basic IF demonstration.
Based on Cloak of Darkness by Roger Firth. (See >ABOUT for more information on the game spec.)

Hurrying through the rainswept November night, you're glad to see the bright lights of the Opera House. It's surprising that there aren't more people about but, hey, what do you expect in a cheap demo game...?

Foyer of the Opera House
You are standing in a spacious hall, splendidly decorated in red and gold, with glittering chandeliers overhead. The entrance from the street is to the north, and there are doorways south and west.

You are wearing a velvet cloak, and you are carrying nothing.

. . .

Entrance to the Opera House
You've only just arrived, and besides, the weather outside seems to be getting worse.

. . .

Examine Self
You're just an everyday opera-lover.

. . .

Examine cloak
A handsome cloak, of velvet trimmed with satin, and slightly spattered with raindrops. Its blackness is so deep that it almost seems to suck light from the room.

. . .

You move south.
Foyer bar
It is pitch dark, and you can't see a thing in here! What's going on?

. . .

You move west.
Cloakroom
The walls of this small room were clearly once lined with hooks, though now only one remains. The exit is a door to the east.

. . .

Foyer bar
Blundering around in the dark isn't a good idea!

. . .

Foyer bar
In the dark? You could easily disturb something! Besides, you are likely to be eaten by a grue!

. . .

Examine hook
It's just a small brass hook, screwed to the wall.

. . .

(Your score has increased by 1)
You remove the velvet cloak and hang it on the hook.

. . .

This isn't the best place to leave a smart cloak lying around.

. . .

About

The various implementations have been made as similar as possible. That is, things like object names and room descriptions should be identical, and the general flow of the game should be pretty comparable. Having said that, the games are implemented using the native capabilities of the various systems, using features that a beginner might be expected to master; there shouldn't be any need to resort to assembler routines, library hacks, or other advanced techniques. The target is to write naturally and simply, while sticking as closely as possible to the goal of making the games directly equivalent.

"Cloak of Darkness" is not going to win prizes for its prose, imagination or subtlety. Or scope: it can be played to a successful conclusion in five or six moves, so it's not going to keep you guessing for long. (On the other hand, it may qualify as the most widely-available game in the history of the genre.) There are just three rooms and three objects.

The Foyer of the Opera House is where the game begins. This empty room has doors to the south and west, also an unusable exit to the north. There is nobody else around.
The Bar lies south of the Foyer, and is initially unlit. Trying to do anything other than return northwards results in a warning message about disturbing things in the dark.
On the wall of the Cloakroom, to the west of the Foyer, is fixed a small brass hook.
Taking an inventory of possessions reveals that the player is wearing a black velvet cloak which, upon examination, is found to be light-absorbent. The player can drop the cloak on the floor of the Cloakroom or, better, put it on the hook.
Returning to the Bar without the cloak reveals that the room is now lit. A message is scratched in the sawdust on the floor.
The message reads either "You have won" or "You have lost", depending on how much it was disturbed by the player while the room was dark.
The act of reading the message ends the game.
And that's all there is to it...

Foyer of the Opera House
You are standing in a spacious hall, splendidly decorated in red and gold, with glittering chandeliers overhead. The entrance from the street is to the north, and there are doorways south and west.

. . .

Entrance to the Opera House
You've only just arrived, and besides, the weather outside seems to be getting worse.

. . .

Examine Self
You're just an everyday opera-lover.

. . .

You move south.
Foyer bar
The bar, much rougher than you'd have guessed after the opulence of the foyer to the north, is completely empty. There seems to be some sort of message scrawled in the sawdust on the floor.

. . .

This plush bar is stained from long years of gin slings, rum punches and other high-class drinks.

. . .

You move west.
Cloakroom
The walls of this small room were clearly once lined with hooks, though now only one remains. The exit is a door to the east.

. . .

Examine hook
It's just a small brass hook, with a cloak hanging on it.

. . .

(Your score has increased by 1)
The message, neatly marked in the sawdust, reads...

"*** You have won ***"

. . .

Foyer of the Opera House
You are standing in a spacious hall, splendidly decorated in red and gold, with glittering chandeliers overhead. The entrance from the street is to the north, and there are doorways south and west.

You are wearing a velvet cloak, and you are carrying nothing.

. . .

Entrance to the Opera House
You've only just arrived, and besides, the weather outside seems to be getting worse.

. . .

Examine Self
You're just an everyday opera-lover.

. . .

Examine cloak
A handsome cloak, of velvet trimmed with satin, and slightly spattered with raindrops. Its blackness is so deep that it almost seems to suck light from the room.

. . .

You move south.
Foyer bar
It is pitch dark, and you can't see a thing in here! What's going on?

. . .

You move west.
Cloakroom
The walls of this small room were clearly once lined with hooks, though now only one remains. The exit is a door to the east.

. . .

Foyer bar
Blundering around in the dark isn't a good idea!

. . .

Foyer bar
In the dark? You could easily disturb something! Besides, you are likely to be eaten by a grue!

. . .

Examine hook
It's just a small brass hook, screwed to the wall.

. . .

(Your score has increased by 1)
You remove the velvet cloak and hang it on the hook.

. . .

Foyer of the Opera House
You are standing in a spacious hall, splendidly decorated in red and gold, with glittering chandeliers overhead. The entrance from the street is to the north, and there are doorways south and west.

. . .

Entrance to the Opera House
You've only just arrived, and besides, the weather outside seems to be getting worse.

. . .

Examine Self
You're just an everyday opera-lover.

. . .

You move south.
Foyer bar
The bar, much rougher than you'd have guessed after the opulence of the foyer to the north, is completely empty. There seems to be some sort of message scrawled in the sawdust on the floor.

. . .

You move west.
Cloakroom
The walls of this small room were clearly once lined with hooks, though now only one remains. The exit is a door to the east.

. . .

The message has been carelessly trampled, making it difficult to read.
You can just distinguish the words...

"You have lost."

. . .

Examine hook
It's just a small brass hook, with a cloak hanging on it.

. . .

This plush bar is stained from long years of gin slings, rum punches and other high-class drinks.

. . .

This isn't the best place to leave a smart cloak lying around.

. . .

This plush bar is stained from long years of gin slings, rum punches and other high-class drinks.

. . .