I've finished the port of Gareth Rees "Through the Looking Glass" tutorial game and would appreciate it if you would take a look at the code and post any suggestions you might have to improve the code.
There are a couple of odd problems that I can't track down here. The script for the white kitten stops running after anything in the game is picked up by the player and the game will only display monospaced type in the Carbon version of Hugo v3.1.02, but it uses proportional type in the GLK Mac version.
I plan to alter the tutorial to make it applicable to Hugo and then ask Gareth Rees for permission to upload it to the IF Archive shortly, but I'd rather wait until I've heard from other Hugo programmers before I start on that. This is my first Hugo project, so I'm sure there are some things I could have handled better here.
Code: Select all
! #set DEBUG
#ifset DEBUG
#switches -d
#endif
verb "untangle", "roll", "wind"
* "up" held DoUntangle
* held "up" DoUntangle
* held DoUntangle
verb "look", "l", "examine", "x", "watch"
* "at" object "in" (mirror) DoReflect
* object "in" (mirror) DoReflect
#set USE_PLURAL_OBJECTS
#set VERBSTUBS
#include "verblib.g"
#include "hugolib.h"
#include "resource.h"
routine DoUntangle
{
"What curious ideas you have!"
}
routine DoReflect
{
if (object = mirror, hearth) or
(player not in mantelpiece and player not in armchair)
"You can't see that in the looking glass."
else
{
"The looking-glass ";
print object.name;
if player in mantelpiece
" looks very misty and blurred."
else
{
" looks just like the real ";
print object.name;
" only all reversed, left for right."
}
}
}
attribute male
replace AssignPronoun(obj)
{
#ifclear OLD_STYLE_PRONOUNS
if obj >= it_object and obj <= them_object
return
#endif
if parser_data[PARSER_STATUS] & PRONOUNS_SET
return
if obj = player
return
if not obj.#noun and not obj.#adjective
return
if obj is plural
them_obj = obj
elseif obj is female
her_obj = obj
elseif obj is male
him_obj = obj
else
it_obj = obj
}
routine init
{
counter = -1
STATUSTYPE = 0
TEXTCOLOR = BLACK
BGCOLOR = BRIGHT_WHITE
SL_TEXTCOLOR = BRIGHT_WHITE
SL_BGCOLOR = BLACK
prompt = ">"
color TEXTCOLOR, BGCOLOR
cls
"It's a cold winter day outside, but in the looking-glass house
it's summer. All you need to do is pretend there's a way of getting
through into it somehow ...\n"
pause
LoadPicture("alice", "alice1")
Font(BOLD_ON | DEFAULT_FONT)
"Through the Looking Glass"
Font(BOLD_OFF)
"An Interactive Tutorial"
print BANNER
player = you
location = drawing_room
old_location = location
move player to location
FindLight(location)
DescribePlace(location)
location is visited
CalculateHolding(player)
setscript[Script(white_kitten, 2)] = &PlayfulKittens, nothing,
&LoopScript, nothing
setscript[Script(black_kitten, 2)] = &PlayfulKittens, nothing,
&LoopScript, nothing
#ifset USE_PLURAL_OBJECTS
InitPluralObjects
#endif
}
routine main
{
counter = counter + 1
PrintStatusLine
run location.each_turn
runevents
RunScripts
if parent(speaking)~=location
speaking = 0
}
player_character you "you"
{
size 55
}
room drawing_room "Drawing Room"
{
long_desc
"The gentle sound of snow against the window pane suggests that
it's cold outside, and you're glad to be here in the warmth.
The drawing room is reflected in the large looking glass on the
wall above the mantelpiece, and a very comfortable room it is
too, with a warm hearth, a soft rug, and an armchair that you
can curl up and sleep in."
before
{
location DoGo
{
if object = d_obj, out_obj
{
if player in mantelpiece
{
"You drop down into the warm and comfortable armchair."
move player to armchair
}
elseif player in armchair
{
"You hop down from the armchair."
move player to drawing_room
}
else
return false
}
elseif object = u_obj
{
if player in armchair and armchair is near_mantel
{
"You clamber up onto the mantelpiece."
move player to mantelpiece
}
else
return false
}
else
return false
}
}
}
scenery window_pane "window"
{
nouns "window", "pane", "snow"
adjectives "window"
article "the"
long_desc
"Outside the window it's snowing gently, and you're glad to be
in here in the warmth."
before
{
object DoOpen
{
"You wouldn't want to catch a chill, would you? Better leave
the window shut."
}
}
is openable
in drawing_room
}
object red_queen "red queen"
{
nouns "queen", "piece"
adjectives "red", "black", "chess"
article "the"
long_desc
"She's a fierce little chess piece."
after
{
object DoGet
{
if white_kitten.currently = PLAYING_WITH_QUEEN
{
white_kitten.currently = PLAYING_WITH_CHAIR
red_queen is not hidden
return false
}
elseif black_kitten.currently = PLAYING_WITH_QUEEN
{
black_kitten.currently = PLAYING_WITH_CHAIR
red_queen is not hidden
return false
}
else
return false
}
object DoPutIn
{
if xobject = chess_board
"Alone on the chess board, the red queen is monarch of all
she surveys."
else
return false
}
}
size 1
is female
}
plural_class missing_pieces
{
nouns "pawns", "rooks", "castles", "knights", "horses", \
"bishops", "queens", "kings", "pieces"
adjectives "missing", "red", "white", "black", "chess"
article "the"
plural_of pawn, rook, knight, bishop, queen, king
before
{
object
{
"Alas, the chess pieces seem to be missing. Those naughty
kittens!"
}
}
}
class missing_piece
{
noun "piece"
adjectives "missing", "white", "chess"
article "the"
plural_is missing_pieces
before
{
object
{
"Alas, that chess piece seems to be missing. Those naughty
kittens!"
}
}
is hidden, static
}
missing_piece pawn "pawn"
{
noun "pawn"
adjectives "red", "black"
in drawing_room
}
missing_piece rook "rook"
{
nouns "rook", "castle"
adjectives "red", "black"
in drawing_room
}
missing_piece knight "knight"
{
nouns "knight", "horse"
adjectives "red", "black"
in drawing_room
}
missing_piece bishop "bishop"
{
noun "bishop"
adjectives "red", "black"
in drawing_room
}
missing_piece queen "queen"
{
noun "queen"
in drawing_room
}
missing_piece king "king"
{
noun "king"
adjectives "red", "black"
in drawing_room
}
object chess_board "chess board"
{
nouns "board", "board"
adjectives "chess", "checker", "chequer"
article "the"
initial_desc
"An abandoned chess board lies on the floor."
long_desc
"It's left here from the game you were playing just now, but the
pieces are all missing--the kittens will insist on playing
with them."
size 3
capacity 5
holding 0
is platform
in drawing_room
}
scenery hearth "hearth"
{
nouns "hearth", "fireplace", "place"
adjective "fire"
article "the"
long_desc
"Looking at the hearth, you wonder if they have a hearth in the
looking-glass house. You can never tell by looking, unless your
fire smokes, and then smoke comes up in the looking-glass room
too--but that may be only pretense, just to make it look as if
they had a fire."
in drawing_room
}
attribute hiding_queen
object rug "rug"
{
nouns "rug", "hearthrug", "carpet"
adjectives "hearth", "indian", "arabian", "soft", "beautiful"
article "the"
long_desc
"It's a beautiful rug, made in some far off country, perhaps
India or Araby, wherever those might be."
before
{
object DoLookUnder
{
if player in self
"You try to lift up a corner of the rug, but fail. After
a while, you realize that this is because you are standing
on it. How curious the world is!"
elseif player in mantelpiece or player in armchair
"You're unable to reach the rug from here."
elseif self is hiding_queen
{
"You lift up a corner of the rug and, peering underneath,
discover the red queen from the chess set."
move red_queen to player
self is not hiding_queen
}
else
return false
}
object DoGet
{
"The rug is much too large and heavy for you to carry."
}
object DoMove, DoPull, DoPush
{
"But a hearth rug is meant to be next to the hearth!"
}
}
capacity 987
holding 0
is hidden, static, platform, enterable, hiding_queen
in drawing_room
}
attribute near_mantel
object armchair "armchair"
{
nouns "chair", "armchair"
adjective "arm", "huge"
article "the"
long_desc
{
"It's a huge armchair, the perfect place for a kitten or a
little girl to curl up in and doze. It has been pushed over
to the ";
{
if self is near_mantel
"fireplace."
else
"window."
}
}
before
{
object DoMove, DoPush, DoPull
{
if white_kitten.currently = PLAYING_WITH_ALICE or
black_kitten.currently = PLAYING_WITH_ALICE
"Not with a kitten in your arms!"
elseif white_kitten.currently = PLAYING_WITH_CHAIR or
black_kitten.currently = PLAYING_WITH_CHAIR
{
local this_kitten
if white_kitten.currently = PLAYING_WITH_CHAIR
this_kitten = white_kitten
else
this_kitten = black_kitten
"You are about to start moving the chair when you
notice that ";
print The(this_kitten);
" is right in the way. It's a good thing you spotted it, or
you would have squashed flat the poor little thing."
}
elseif player not in drawing_room
{
"You'll have to get off ";
print The(parent(player));
" first."
}
elseif self is near_mantel
{
"You push the armchair away from the hearth."
self is not near_mantel
}
else
{
"You push the armchair over to the hearth."
self is near_mantel
}
}
object DoClimb, DoEnter
{
"You jump into the warm and comfortable armchair."
move player to armchair
}
}
capacity 233
holding 0
reach mantelpiece
is hidden, static, platform, enterable, not near_mantel
in drawing_room
}
object mantelpiece "mantelpiece"
{
nouns "mantelpiece", "mantel"
article "the"
long_desc
"It's higher off the ground than your head, but it looks wide
enough and sturdy enough to support you."
before
{
object DoEnter, DoClimb
{
if player not in armchair and armchair is not near_mantel
"You can't reach the mantelpiece from here."
elseif WhatsIn(player) > 0
"Your hands are too full."
else
{
"You scramble up onto the mantelpiece."
move player to mantelpiece
}
}
object DoExit
{
"You jump into the warm and comfortable armchair."
move player to armchair
}
xobject DoPutIn, DoTakeOff
{
if player not in self and
(player not in armchair or armchair is not near_mantel)
"The mantelpiece is so high that you can't reach."
else
return false
}
}
capacity 144
holding 0
reach armchair, mirror
is hidden, static, platform, enterable
in drawing_room
}
object mirror "looking glass"
{
nouns "mirror", "glass"
adjectives "looking"
article "the"
long_desc
{
if player in mantelpiece
"Strangely, the glass is beginning to melt away, just like
a bright silvery mist."
elseif player in armchair
"In the looking glass you can see the drawing room of the
looking-glass house. What you can see is very much the same
as this drawing room, only all reversed, left for right.
But you are sure that out of the corners of the glass, where
you can't see, the looking-glass world is quite different
from yours."
else
"In the looking glass you can see the ceiling of the drawing
room of the looking-glass house. It looks much the same as
the ceiling of your drawing room."
}
before
{
object
{
if player not in mantelpiece
{
if verbroutine = &DoLook
return false
else
"You can't reach the looking glass from where you're
standing."
}
elseif verbroutine = &DoTouch, &DoMove, &DoPush, &DoPull
"Your hand goes right through the silvery mist!"
elseif verbroutine = &DoEnter
{
"Your hand goes right through the silvery mist, and in
another moment the rest of you follows, and you are through
the glass ..."
LoadPicture("alice", "alice3")
endflag = true
}
else
return false
}
xobject DoThrowAt
{
"You don't want seven years of bad luck, do you?"
}
}
is hidden, static
in drawing_room
}
attribute tangled
object worsted "ball of worsted"
{
nouns "ball", "wool", "worsted"
adjectives "blue", "fine", "ball"
article "a"
initial_desc
"A discarded ball of worsted lies on the floor here."
long_desc
{
if self is tangled
"It's in a terrible tangle. All that time you spent rolling
it up, and now look at it!"
else
"It's a ball of fine blue wool, all rolled up in preparation
for some embroidery."
}
before
{
object DoUntangle
{
if self is tangled
{
"You're as quick as can be at rolling up balls of wool,
though you say so yourself! Soon it's neat and tidy again."
self is not tangled
}
else
"But someone already has! The ball of wool is neat and tidy."
}
}
after
{
object DoGet
{
if white_kitten.currently = PLAYING_WITH_BALL
{
worsted is not hidden
white_kitten.currently = PLAYING_WITH_CHAIR
return false
}
elseif black_kitten.currently = PLAYING_WITH_BALL
{
worsted is not hidden
black_kitten.currently = PLAYING_WITH_CHAIR
return false
}
else
return false
}
}
size 1
is not tangled
in drawing_room
}
attribute playing
property other_kitten
property currently
enumerate
{
PLAYING_WITH_CHAIR, PLAYING_WITH_ALICE, PLAYING_WITH_QUEEN,
PLAYING_WITH_BALL
}
class kitten
{
nouns "kitten", "kitty", "cat"
article "a"
short_desc
{
if self.currently = PLAYING_WITH_QUEEN
{
print CArt(self);
" is playing with the red queen."
}
elseif self.currently = PLAYING_WITH_BALL
{
print CArt(self);
" is playing with a ball of worsted."
}
elseif self.currently = PLAYING_WITH_CHAIR
{
if self.other_kitten.currently = PLAYING_WITH_CHAIR
{
"Two kittens, one white and one black, are playing together
by the armchair."
self.other_kitten is already_listed
}
else
{
print CArt(self);
" is playing by the armchair."
}
}
else
return false
}
long_desc
{
"What a beautiful kitten ";
print The(self);
" is. Why, it's quite definitely your favorite of the pair, and
much prettier than that naughty ";
print self.other_kitten.name; "."
}
ignore_response
{
print CThe(self);
" twitches its whiskers and looks at you with such a clever
expression that you are certain it understands every word you
are saying."
}
before
{
object DoGet
{
if self.other_kitten in player
"You can't hold two kittens at once!"
else
{
self.currently = PLAYING_WITH_ALICE
move self to player
"You pick up ";
print The(self);
". What a beautiful creature it is!"
}
}
xobject DoThrowAt
{
if object ~= red_queen, worsted
{
move object to drawing_room
"You toss ";
print The(object);
" onto the floor. "
Perform(&DoGive, object, self)
}
else
Perform(&DoGive, object, self)
}
}
after
{
object DoDrop, DoPutOnGround
{
self.currently = PLAYING_WITH_CHAIR
move self to drawing_room
print CThe(self);
" squirms out of your arms and scampers away."
}
object DoPutIn
{
self.currently = PLAYING_WITH_CHAIR
print CThe(self);
" jumps off ";
print The(parent(self));
", landing lightly on the floor before scampering away."
move self to drawing_room
}
object DoKiss
{
"You give ";
print The(self);
" a little kiss on its nose, and it looks sweetly and demurely
at you."
}
object DoHit
{
"You would never do such a beastly thing to such a defenseless
little animal!"
}
xobject DoShow
{
print CThe(self);
" bats a paw at ";
print The(object); "."
}
xobject DoGive
{
if object ~= red_queen, worsted
{
print CThe(self);
" just examines ";
print The(object);
" with a quizzical expression."
}
else
{
move object to drawing_room
"You toss ";
print The(object);
" onto the floor and ";
print The(self);
if self in player
{
move self to drawing_room
" squirms out of your grasp and";
}
" scampers after it";
if object = worsted
{
self.currently = PLAYING_WITH_BALL
worsted is hidden
worsted is tangled
", quickly turning the neat ball into a tangle";
}
else
self.currently = PLAYING_WITH_QUEEN
red_queen is hidden
"."
if object = worsted
LoadPicture("alice", "alice2")
}
}
}
currently PLAYING_WITH_CHAIR
size 5
is living
}
plural_class kittens
{
nouns "kittens", "kitties", "cats"
single_noun "kitten"
plural_of white_kitten, black_kitten
}
kitten white_kitten "white kitten"
{
adjective "white"
plural_is kittens
other_kitten black_kitten
is playing
in drawing_room
}
kitten black_kitten "black kitten"
{
adjective "black"
plural_is kittens
other_kitten white_kitten
is not playing
in drawing_room
}
routine PlayfulKittens
{
local this_kitten, activity
activity = random(5)
if this_kitten is playing
{
this_kitten is not playing
if random(3) = 3
return false
else
{
indent
print CThe(this_kitten);
select this_kitten.currently
case PLAYING_WITH_ALICE
{
select activity
case 1
" mews plaintively."
case 2
" purrs quietly to itself."
case 3
" purrs contentedly to itself."
case 4
" rubs its ears against you."
case 5
{
move this_kitten to drawing_room
this_kitten.currently = PLAYING_WITH_CHAIR
" squirms out of your arms and scampers away."
}
}
case PLAYING_WITH_QUEEN
{
select activity
case 1
" bats at the red queen with its paw."
case 2
" stops playing and sits up, pretending to be
innocent of any kittenish tendencies."
case 3
" knocks the red queen across the floor and chases
after it."
case 4
" stops to wash itself."
case 5
" bites the red queen and shakes it to make sure that
it's dead."
}
case PLAYING_WITH_BALL
{
select activity
case 1
" bats at the ball of worsted with its paw."
case 2
" pushes the ball of worsted across the floor and
chases after it."
case 3
" leaps onto the ball of worsted and grapples bravely
with it."
case 4
" jumps into the ball of worsted and gets tangled up
in a mess of threads."
case 5
" stops playing and scratches its ears."
}
case PLAYING_WITH_CHAIR
{
if this_kitten.other_kitten.currently = \
PLAYING_WITH_CHAIR and random(2) = 2
{
select activity
case 1
" chases after ";
case 2
" jumps on top of ";
case 3
" washes ";
case 4
" scampers around the armchair and ";
case 5
" bats at ";
print The(this_kitten.other_kitten);
select activity
case 1, 3
"."
case 2
" and they roll around on the floor."
case 4
" chases after it."
case 5
" with its paw."
}
else
select activity
case 1
" scampers after a speck of dust."
case 2
" rolls around on the floor."
case 3
" sits up and washes its tail."
case 4
" scratches its head on the armchair."
case 5
" chases its tail."
}
}
}
else
{
this_kitten is playing
return false
}
}
resource "alice"
{
"alice1.jpg"
"alice2.jpg"
"alice3.jpg"
}