# Cloak of Darkness tutorial source code
#
name Cloak of Darkness
version Tutorial.1.0
author Mike Arnautov
date 24 Feb 2024
style 12
#----------------------------------------------------------------------
text YOU.ARRIVE
   The Cloak of Darkness

   Hurrying through the rain-swept 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...?

#----------------------------------------------------------------------
# Game specification mandates just the four cardinal directions
verb NORTH
verb EAST
verb SOUTH
verb WEST
#
verb GET, TAKE    # Both the player and game code can use these interchangeably
verb INVENTORY
verb DROP
verb READ         # For reading the message in the bar room
verb HANG         # To hang the cloak on the hook
verb LOOK
verb QUIT         # Not in the spec, but every game should allow quitting
#
noise THE, THAT, VELVET, GO     # Player command words to be ignored
#----------------------------------------------------------------------
object HOOK
  %A small brass hook is screwed to one wall.
  &It is just a small brass hook[/ with a cloak hanging on it].
#----------------------------------------------------------------------
object CLOAK
   A velvet cloak[ (worn)/]
  %A black velvet cloak [/lies on the floor/hangs on the hook].
  &It is 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.
#----------------------------------------------------------------------
object MESSAGE  
   The message[ has been carelessly trampled, making it difficult to read.
   You can just distinguish the words/, neatly marked in the sawdust,
   reads]...

   +YOU HAVE [LOST/WON] !!!
#----------------------------------------------------------------------
place FOYER
   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.
place 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.
place BAR
   [It is too dark here to see anything!/The bar, much rougher than
   you'd have guessed after the opulence of the foyer to the north, 
   is completely empty.

   A message is scratched in the sawdust on the floor.]
#----------------------------------------------------------------------
init
   goto foyer              # Move the player to the start location
   apport cloak, inhand    # Give him the cloak
   apport hook, cloakroom  # Put the hook where it belongs
   set message, 4          # Limits the number of moves in the bar
   say you.arrive
#----------------------------------------------------------------------
repeat   
   ifflag status, moved   # Has the player moved?
      call describe.here  # If so describe their new location
   fin
#----------------------------------------------------------------------
flags variable
   MOVED      # Optional STATUS variable flag, maintained by the kernel
#----------------------------------------------------------------------
proc DESCRIBE.HERE
   local optr       # Local pointer to objects
   say here         # show description of current location
   itobj optr, here # Loop through objects at this location
      say optr      # Show such objects
   fin              # Loop terminator
#----------------------------------------------------------------------
repeat
   set status, no.amatch    # Suppress approximate matching of command words
   input          # Get player's next command
   ifeq status, 2 
      and
   iflt arg2, 0   # Can't find 2nd command word in the vocabulary
      or
   iflt arg1, 0   # Can't find 1st command word in the vocabulary
      quip "Pardon?"      # Command parse failure -- abort the main loop
   fin
#----------------------------------------------------------------------
repeat
   ifkey quit     # If the word QUIT occurs in the command
      say "As you wish."
      stop        # Exit the game
   fin
   call here      # Execute code, if any, associated with this location
   respond north, east, south, west, "There is no such exit here."
   call arg1      # Handle player command
   call bail.out  # Command not handled - report an error
#----------------------------------------------------------------------
proc bail.out
   local qualifier            # Local varaible initialised to zero
   ifeq status, 1             # If a single word command given
     ifflag arg1, object      # If that word is an object name
       ifnear arg1
       else
         quip "There is no # here!", arg1
       fin
     else
       set qualifier, 1       # The word is not an object name, assume verb
     fin
     quip "You need to say what you want to [do with the /]{arg1}.", qualifier
   fin
   quip "You can't do that!"  # Generic no can do
#----------------------------------------------------------------------
at foyer
   move south, bar
   move west, cloakroom
   respond north "You've only just arrived, and besides, the weather outside 
      seems to be getting worse."
#----------------------------------------------------------------------
at cloakroom
   move east, foyer
at bar
   move north, foyer
   ifloc cloak, cloakroom
   else                     # The cloak is not in the cloakroom
      sub message, 1        # Count attempted actions in the dark
      quip "Blundering around in the dark isn't a good idea!"
   fin
#----------------------------------------------------------------------
action inventory
   local optr  # Local variable which will be used as a pointer to objects
   local count # Counts listed objects, automatically initialised to zero
   itobj optr, inhand # Loop through objects in player's inventory
      say optr        # Show object's description
      add count, 1    # Increment count of listed objects
   fin
   ifeq count, 0                           # If nothing listed, ...
      say "You are not carrying anything." # ... say empty-handed
   fin
   quit        # Command fully handled, so terminate the REPEAT loop
#----------------------------------------------------------------------
action take inventory
   call inventory     # Execute code associated with the INVENTORY command
#----------------------------------------------------------------------
action take cloak
   ifhere cloak     # If cloak is at this location
      get cloak
      set cloak, 1  # The cloak is now carried
      set bar, 0    # and the bar is now dark
      quip "You [/pick/take] the cloak[/ up/ off the hook].", cloak
   fin
#----------------------------------------------------------------------
action drop cloak
   ifhave cloak       # True only if the player has the cloak
      ifat cloakroom  # True only if player is at cloakroom
         drop cloak   # Move the cloak from player's inventory to cloakroom
         set cloak, 1 # It is now lying on the floor
         set bar, 1   # The bar is now lit
         quip "You drop the cloak."
      fin
      quip "This is not a good place to leave your cloak."
   fin
#----------------------------------------------------------------------
action hang cloak
   ifnear cloak
      ifat cloakroom     # True only if the player is at the cloakroom   
         ifeq cloak, 2   # Already hanging -- nothing to do 
           quip "It is already hanging on the hook!"
         fin
         ifhave, cloak   # True only if the cloak is in the players' possession
           drop cloak    # Make sure it is not carried
         fin
         set hook, 1     # Include the cloak in the hook's description
         set cloak, 2    # Set the cloak to have no description
         set bar, 1      # Bar is now lit
         quip "You hang the cloak on the hook."
      fin
   fin
#----------------------------------------------------------------------
action read
   ifeq status, 1     # Player said READ - we'll default to READ MESSAGE
      or
   ifkey message      # Player actually said READ MESSAGE
      and
   ifat bar           #Player is at the bar
      and
   ifeq bar, 1        # If the bar is lit
      say message     # "Lost" or "won", depends on the message's value
      stop
   fin
#----------------------------------------------------------------------
action look
   ifeq status, 1
      call describe.here  # The procedure does not QUIT...
      quit                # ... so QUIT explicitly
   fin
   ifnear arg2
      ifkey message   # If the object to be describe is the message...
         call read    # ... just call the code for READ.
      fin
      describe arg2   # Otherwise give long object description
      quit
   fin
#----------------------------------------------------------------------

Back to the documentation index
To the Mipmip home page
Feel free to leave a comment!
Mike Arnautov (07 March 2024)