~ubuntu-branches/ubuntu/vivid/inform/vivid

« back to all changes in this revision

Viewing changes to html/answers2/answer66.html

  • Committer: Bazaar Package Importer
  • Author(s): Jan Christoph Nordholz
  • Date: 2008-05-26 22:09:44 UTC
  • mfrom: (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526220944-ba7phz0d1k4vo7wx
Tags: 6.31.1+dfsg-1
* Remove a considerable number of files from the package
  due to unacceptable licensing terms.
* Repair library symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<HTML><HEAD><TITLE>Answer to Exercise 66</TITLE></HEAD>
2
 
<BODY BGCOLOR="#FFFFFF">
3
 
<TABLE><TR><TD Valign="top"><IMG SRC="../icons/exercise.gif" ALT="??"><TD bgcolor="#FAA89B"><B>ANSWER TO EXERCISE 66</B><TR><TD><TD>
4
 
<P>
5
 
 
6
 
 
7
 
The scheme will work like this: any room that ought to have a name
8
 
should have a <TT>place_name</TT> property set to a dictionary word;
9
 
say, the Bedquilt cave could be called <TT>'bedquilt'</TT>.  Clearly
10
 
you should only be allowed to type this from adjacent rooms.
11
 
So we'll implement the following: you can only move by name to
12
 
those rooms listed in the current room's <TT>to_places</TT> property.
13
 
For instance, the Soft Room might have <TT>to_places</TT> set to
14
 
<PRE>
15
 
to_places Bedquilt Slab_Room Twopit_Room;
16
 
</PRE>
17
 
 
18
 
Now the code: if the player's verb is not otherwise understood,
19
 
we'll check it to see if it's a place name of a nearby room,
20
 
and if so store that room's object number in <TT>goto_room</TT>, converting
21
 
the verb to <TT>'go#room'</TT> (which we'll deal with below).
22
 
<PRE>
23
 
Global goto_room;
24
 
[ UnknownVerb word p i;
25
 
    p = location.&#38;to_places; if (p==0) rfalse;
26
 
    for (i=0:(2*i)&#60;location.#to_places:i++)
27
 
        if (word==(p--&#62;i).place_name)
28
 
        {   goto_room = p--&#62;i; return 'go#room';
29
 
        }
30
 
    rfalse;
31
 
];
32
 
[ PrintVerb word;
33
 
    if (word=='go#room')
34
 
    {   print "go to ", (name) goto_room; rtrue; }
35
 
    rfalse;
36
 
];
37
 
</PRE>
38
 
 
39
 
(The supplied <TT>PrintVerb</TT> is icing on the cake: so the parser can
40
 
say something like "I only understood you as far as wanting to go to
41
 
Bedquilt.'' in reply to, say, "bedquilt the nugget''.)  It remains
42
 
only to create the dummy verb:
43
 
<PRE>
44
 
[ GoRoomSub;
45
 
    if (goto_room hasnt visited) "But you have never been there.";
46
 
    PlayerTo(goto_room);
47
 
];
48
 
Verb "go#room"  *                                -&#62; GoRoom;
49
 
</PRE>
50
 
 
51
 
Note that if you don't know the way, you can't go there!  A purist might
52
 
prefer instead to not recognise the name of an unvisited room, back at
53
 
the <TT>UnknownVerb</TT> stage, to avoid the player being able to deduce names
54
 
of nearby rooms from this 'error message'.}
55
 
<P>
56
 
</TABLE>
57
 
<HR>Back to <A HREF="../section26.html#ex66">the exercise in section 26</A><HR>
58
 
<SMALL><I>Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright &#169; Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.</I></SMALL></BODY></HTML>