
An adventure is more than rooms: there are things to find, and the player's pockets to put them in. BEACON has six that can be carried: a crowbar, a lantern, an oil can, the keeper's logbook, a box of matches and an iron key. This section puts them in the world and lets the player pick them up.
Thing = record
Name: Str20;
Place: Integer;
end;
Name is what the game prints: a crowbar, the logbook. Place is where it is: a room number, or 0 for carried. In S20, -1 will mean "hidden". Six of them make Obj, and Start gives each its name and place when the game begins.
Their numbers line up with their nouns: thing 1, the crowbar, is noun token 20; thing 6, the key, is 25. So the thing a noun means is N1 - 19, and a noun outside 1 to 6 (DOOR, LAMP) is not something you can carry.
Carried(T) asks whether thing T is held: its place is 0. Near(T) asks whether it is held or in this room: the test for anything the player uses.
Look now ends by listing what is in the room: You can see a crowbar.INVENTORY, or I, lists what is carried, or nothing.TAKE checks the noun is a thing, not already carried, and here, then sets its place to 0. DROP sets it to the room.EXAMINE and READ (the same procedure) show the logbook's message, the boat's and the ship's when they are there, and otherwise You see nothing special.And one rule in the main program: the verbs from TAKE to READ, tokens 10 to 17, need a noun. Without one, the game asks: What do you want to TAKE?
The const part gains Things = 6;, the type part gains Str20 = string[20]; and the Thing record above, and the variables gain Obj: array[1..Things] of Thing;.
After Load, add Start:
procedure Start;
begin
Obj[1].Name := 'a crowbar';
Obj[1].Place := 2;
Obj[2].Name := 'a lantern';
Obj[2].Place := 3;
Obj[3].Name := 'an oil can';
Obj[3].Place := 4;
Obj[4].Name := 'the logbook';
Obj[4].Place := 6;
Obj[5].Name := 'a box of matches';
Obj[5].Place := 7;
Obj[6].Name := 'an iron key';
Obj[6].Place := 8;
Here := 1;
Quit := False;
end;
After Parse, add:
function Carried(T: Integer): Boolean;
begin
Carried := Obj[T].Place = 0;
end;
function Near(T: Integer): Boolean;
begin
Near := (Obj[T].Place = 0) or
(Obj[T].Place = Here);
end;
Look becomes:
procedure Look;
var
T: Integer;
begin
Writeln;
Writeln(Map[Here].Name);
Say(Here);
for T := 1 to Things do
if Obj[T].Place = Here then
Writeln('You can see ', Obj[T].Name,
'.');
end;
After Walk, add:
procedure Inventory;
var
T: Integer;
Any: Boolean;
begin
Any := False;
Writeln('You are carrying:');
for T := 1 to Things do
if Carried(T) then
begin
Writeln(' ', Obj[T].Name);
Any := True;
end;
if not Any then
Writeln(' nothing.');
end;
procedure Take;
var
T: Integer;
begin
T := N1 - 19;
if (T < 1) or (T > Things) then
Writeln('You can''t take that.')
else if Carried(T) then
Writeln('You already have it.')
else if Obj[T].Place <> Here then
Writeln('It isn''t here.')
else
begin
Obj[T].Place := 0;
Writeln('Taken.');
end;
end;
procedure Drop;
var
T: Integer;
begin
T := N1 - 19;
if (T < 1) or (T > Things) then
Writeln('You can''t drop that.')
else if not Carried(T) then
Writeln('You haven''t got it.')
else
begin
Obj[T].Place := Here;
Writeln('Dropped.');
end;
end;
procedure Examine;
begin
if (N1 = 23) and Near(4) then
Say(14)
else if (N1 = 30) and (Here = 3) then
Say(26)
else if (N1 = 31) and (Here = 12) then
Say(27)
else
Writeln('You see nothing special.');
end;
Act becomes:
procedure Act;
begin
case V of
1..6: Walk(V);
7: if (N1 > 0) or (P > 0) then
Writeln('Which way?')
else
Writeln('Go where?');
8: Look;
9: Inventory;
10: Take;
11: Drop;
12, 17: Examine;
18: Quit := True;
else
Writeln('You can''t do that yet.');
end;
end;
And the main program:
begin
Load;
Start;
Writeln('BEACON');
Look;
repeat
Write('> ');
GetLine(Line);
if Parse(Line) then
if V = 0 then
Writeln('There is no verb in that.')
else if (V in [10..17]) and
(N1 = 0) then
Writeln('What do you want to ',
Line, '?')
else
Act;
until Quit;
Close(Msg);
end.
For now the matches lie in the kitchen and the key in the bedroom, in plain sight. S20 hides them.
Starting from
BEACON2, read into a new work file BEACON3. Save before you run.
What you should see
> I
You are carrying:
nothing.
> W
Cove
...
You can see a crowbar.
> TAKE CROWBAR
Taken.
> TAKE CROWBAR
You already have it.
> TAKE
What do you want to TAKE?
and in the front room, EXAMINE LOGBOOK prints the keeper's log.
Start, change the lantern's place from 3 to 0. What does I say when the game begins?Take, take out Obj[T].Place := 0;. Take the crowbar, then look at I. What has gone wrong?[10..17] to [11..17]. What does TAKE alone say now, and why?19.1 Let the player carry no more than four things: You can't carry any more.
19.2 Make DROP say what was dropped: You drop a crowbar.
19.3 Make EXAMINE say what any thing is when it is near: It is a lantern.
Worked solutions are in Appendix II.
Each thing is a record of a name and a place: a room, or 0 for carried. Its noun's token, less 19, is its number. TAKE, DROP, INVENTORY and EXAMINE are a few lines each, and verbs that need a noun ask for one.
S20, Locks, Lamps And Logbooks: the puzzles.
This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.