# Appendix C: Tutorial Game Source Code

    #!../bin/jacl

    constant GAME_VERSION		1
    constant GAME_TITLE			"Tutorial Game"
    constant GAME_AUTHOR		"Stuart Allen"
    constant IFID				"JACL-001"

    string 	 command_prompt		"^What do you want to do now? "

    constant turns_since_last_sip		5

    attribute EXAMINED

    location bedroom : master bedroom
     west		bathroom
     south		nowhere

    {look
    print:
       You are in your bedroom. There is a large, soft bed
       in the centre of the room while a doorway to the
       west leads into the bathroom.
    .
    write "To the south there is "
    if door has CLOSED
       write "closed"
    else
       write "open"
    endif
    write " door.^"
    }

    {movement
    if compass = south
       if destination = nowhere
          write "The bedroom door is closed.^"
          return true
       endif
    endif
    return false
    }

    object bed: bed
      short		a "bed"
      mass		scenery

    {look_under
    if guide(parent) = limbo
       write "Hidden under the bed you find this week's "
       write "television guide.^"
       set guide(parent) = here
       points 50
       return
    endif
    write "You don't find anything else.^"
    }

    object guide: television tv tele guide
      short		a "television guide"
      long		"The television guide is here."
      parent	limbo
      mass		5

    {examine : read
    write "It contains a listing of this week's programmes.^"
    }

    {give_to_rick : show_to_rick
    print:
       ~Cool!~ Rick exclaims as he snatches it from your
       hands.^^
       Satisfied that you have achieved at least one thing
       today, you decide to go back to bed.^
    .
    points 50
    execute "+game_over"
    }

    object door : bedroom door
     short		the "bedroom door"
     has		CLOSABLE CLOSED

    {open_override
    set bedroom(south) = living_room
    set living_room(north) = bedroom
    return false
    }

    {close_override
    set bedroom(south) = nowhere
    set living_room(north) = nowhere
    return false
    }

    location bathroom : bathroom
     east		bedroom

    {look
    print:
       You are in the bathroom. The only exit
       from here is back east into the bedroom.^
    .
    }

    {movement
    if compass = east : compass = out
       write "You bang your head as you walk through the "
       write "doorway.^^"
       return false
    endif
    write "The only exit from here is to the east.^"
    }

    object box: small wooden box
      has		CONTAINER CLOSABLE CLOSED
      short		a "small wooden box"
      long		"There is a small wooden box here."
      mass		25
      quantity	20

    {close_override
    write "The lid creaks as you push it closed.^"
    ensure box has CLOSED
    }

    object note: orange note
      short		an "orange note"
      long		"An orange note rests on the ground."
      parent 	box
      mass		5

    {read : examine
    write "The note reads, ~Welcome to Jamaica and have a nice day.~^"
    }

    location living_room: living room
      short		the "living room"
      north		nowhere

    {look
    if here has VISITED
       write "You have returned to the living room.^"
    else
       print:
          You are in the living room. There is a small
          television perched on a low-lying table in front
          of a sofa.
       .
       write "To the north there is "
       if door has CLOSED
          write "closed"
       else
          write "open"
       endif
       write " door.^"
    endif
    }

    {movement
    if compass = north
       if destination = nowhere
          write "The bedroom door is closed.^"
          return true
       endif
    endif
    return false
    }

    {eachturn : *eachturn_bedroom
    move door to here
    }

    object television: television tv tele
      short		a "television"
      mass		scenery

    {examine
    if self has EXAMINED
       write "It's Rick who is the TV addict, not you.^"
       return
    endif
    write "There is currently a cartoon showing on the "
    write "television.^"
    ensure self has EXAMINED
    }

    {turn_off
    print:
       As you reach over and switch off the television,
       you get quite a shock to see Rick rapidly growing
       a coat of hair and foaming at the mouth. The shock
       of this is only surpassed by that of him sinking
       his newly-acquired fangs into your throat.^
    .
    execute "+game_over"
    }

    {turn_on
    write "The television is already on."
    }

    object rick: son boy teenager rick
      has		ANIMATE
      short		name "Rick"
      long		"Rick is here, watching television."
      mass		heavy

    {examine
    write "Rick is staring blankly at the television screen.^"
    }

    {tell_about_guide
    print:
       ~Oh, you found it, great. Give it to me!~ Rick exclaims.^
    .
    }

    {tell_about_kryten
    print:
       Rick starts to nod off as you tell him all about your early childhood.^
    .
    }

    {ask_about_rick
    print:
       ~My life is all but ruined until you find the TV guide.^
    .
    }

    {ask_about_television
    print:
       ~It could be bigger,~ Rick says with a sigh.^
    .
    }

    {talk_to
    print:
       ~Uh, yeah, I'll do it in a minute,~ Rick mumbles
       with out looking up. You have quite a strong
       suspicion that he didn't really hear a word
       you said.^
    .
    }

    #-----------------------------------------------------------------------------
    # GLOBAL FUNCTIONS
    #-----------------------------------------------------------------------------

    {+eachturn
    set rick(turns_since_last_sip) + 1
    if rick(turns_since_last_sip) = 5
       if here = living_room
          write "Rick takes a sip from his drink.^"
      endif
      set rick(turns_since_last_sip) = 0
    endif
    }

    {+default_ask_about
    if noun1 = rick
       print:
          Rick pokes out his bottom lip then blinks several
          times. This, you have figured out over the
          years, translates to, ~Not a clue.~^
       .
       return
    endif
    return false
    }

    {+intro
    style bold
    write "^^" GAME_TITLE
    style normal
    write " by " GAME_AUTHOR "^^"

    print:
       Your alarm rings and you climb out of bed.
       Monday morning again so soon. Oh well, at least
       your house doesn't have a front door so you have
       a good excuse for not going to work.^^
    .

    if here hasnt OUTDOORS
      set north_wall(parent) = here
      set south_wall(parent) = here
      set east_wall(parent) = here
      set west_wall(parent) = here
    endif
    set ground(parent) = here
    look
    }

    {+game_over
    write "^"
    execute "+score"
    endgame
    }

    object kryten: myself self me
     has		ANIMATE
     short		name "yourself"
     quantity	42
     parent		bedroom
     player

    {examine
    write "As beautiful as ever.^"
    execute "+inventory"
    }

    grammar about >about

    {+about
    write "This is the game from the tutorial section of the JACL Author's Guide."
    write "See the appendix for the full source to this program.^"
    }

    integer OFFSET
    integer INDEX
    string status_text "temp"
    constant status_window 3

    {+update_status_window
    style reverse
    padstring status_text " " status_width
    write status_text
    cursor 0 1
    write status_text
    cursor 0 2
    write status_text
    cursor 1 1
    write here{The}
    setstring status_text "Score: " score " Moves: " total_moves
    set OFFSET = status_width
    length INDEX status_text
    set OFFSET - INDEX
    set OFFSET - 1
    cursor OFFSET 1
    write status_text
    style normal
    }

    object north_wall: north north wall
     has			NO_TAB
     short          the "north wall"

    object south_wall: south southern wall
     has			NO_TAB
     short          the "south wall"

    object east_wall: east eastern wall
     has			NO_TAB
     short          the "east wall"

    object west_wall: west western wall
     has			NO_TAB
     short          the "west wall"

    object ground: ground floor
     has            SURFACE NO_TAB
     short          the "ground"

    #include "verbs.library"

Back to Contents