Turbo Pascal Text Adventure Primer cover: BEACON, the adventure the primer builds in Turbo Pascal 2.0, mid-game on the Tatung Einstein
← Back to Modules
module
20

Locks, Lamps And Logbooks

Introduction

Twelve rooms and six things make a world to walk about in. Puzzles make it a game. BEACON has four, and every one is the same idea: something the game remembers, a flag, that the player's actions set and that other actions test.

The Four Puzzles

PuzzleThe flagSet byTested by
The shed door is nailed shutShedOpenOPEN DOOR WITH CROWBAR on the beachgoing east from the beach
The tower is lockedTowerOpenUNLOCK DOOR WITH KEY at its footgoing up from the base
The stairs are darkLitLIGHT LANTERN, with the matchesgoing up the stairs, with the lantern carried
The great lamp is dryFilledFILL LAMP WITH OIL in the lamp roomLIGHT LAMP

And a fifth flag, Won, set when the great lamp is lit, ends the game.

Hidden things. The matches start in the kitchen cupboard and the key in the bedroom drawer, out of sight: their place is -1, which is no room, so Look never lists them. OPEN CUPBOARD in the kitchen says what is inside and sets the matches' place to the kitchen, and from then on they are there to take.

Two nouns. OPEN DOOR WITH CROWBAR is verb 13, noun 26, preposition 40, noun 20. Open checks the second noun is the right one, and that it is carried. UNLOCK is handled by the same procedure as OPEN.

Everything the game says is a message. Say(16) is the nailed door, Say(21) the ending: the code holds message numbers and the disc holds the words.

The Code

The variables become:

var
  Map: array[1..Rooms] of Room;
  Obj: array[1..Things] of Thing;
  Msg: file of Str255;
  Here, V, N1, P, N2: Integer;
  ShedOpen, TowerOpen, Lit, Filled,
  Won, Quit: Boolean;
  Line: Str40;

Start hides the matches and the key (place -1) and clears the flags. Here is all of it:

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 := -1;
  Obj[6].Name := 'an iron key';
  Obj[6].Place := -1;
  Here := 1;
  ShedOpen := False;
  TowerOpen := False;
  Lit := False;
  Filled := False;
  Won := False;
  Quit := False;
end;

Walk becomes, with the three ways that can be shut:

procedure Walk(D: Integer);
var
  Dest: Integer;
begin
  Dest := Map[Here].Exits[D];
  if (Here = 1) and (D = 3)
     and not ShedOpen then
    Say(16)
  else if (Here = 9) and (D = 5)
     and not TowerOpen then
    Say(15)
  else if (Here = 10) and (D = 5)
     and not (Lit and Carried(2)) then
    Say(13)
  else if Dest = 0 then
    Writeln('You can''t go that way.')
  else
  begin
    Here := Dest;
    Look;
  end;
end;

After Drop, add the three new verbs:

procedure Open;
begin
  if (N1 = 27) and (Here = 7) then
  begin
    if Obj[5].Place = -1 then
    begin
      Say(24);
      Obj[5].Place := 7;
    end
    else
      Writeln('It is already open.');
  end
  else if (N1 = 28) and (Here = 8) then
  begin
    if Obj[6].Place = -1 then
    begin
      Say(25);
      Obj[6].Place := 8;
    end
    else
      Writeln('It is already open.');
  end
  else if (N1 = 26) and (Here = 1) then
  begin
    if ShedOpen then
      Writeln('It is already open.')
    else if (N2 = 20) and Carried(1) then
    begin
      Say(17);
      ShedOpen := True;
    end
    else
      Say(16);
  end
  else if (N1 = 26) and (Here = 9) then
  begin
    if TowerOpen then
      Writeln('It is already open.')
    else if (N2 = 25) and Carried(6) then
    begin
      Say(18);
      TowerOpen := True;
    end
    else
      Say(15);
  end
  else
    Writeln('You can''t open that.');
end;

procedure Light;
begin
  if not Carried(5) then
    Say(23)
  else if N1 = 21 then
  begin
    if not Near(2) then
      Writeln('It isn''t here.')
    else if Lit then
      Writeln('It is already lit.')
    else
    begin
      Say(19);
      Lit := True;
    end;
  end
  else if (N1 = 29) and (Here = 11) then
  begin
    if not Filled then
      Say(22)
    else
    begin
      Say(21);
      Won := True;
    end;
  end
  else
    Writeln('You can''t light that.');
end;

procedure Fill;
begin
  if (N1 <> 29) or (Here <> 11) then
    Writeln('You can''t fill that.')
  else if not Carried(3) then
    Writeln('You have nothing to fill',
            ' it with.')
  else if Filled then
    Writeln('It is already full.')
  else
  begin
    Say(20);
    Filled := True;
    Obj[3].Name := 'an empty oil can';
  end;
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;
    13, 14: Open;
    15: Light;
    16: Fill;
    18: Quit := True;
    19: Writeln('Nothing happens.');
  end;
end;

And in the main program, until Quit; becomes until Won or Quit;.

Starting from

BEACON3, read into a new work file BEACON4. Save before you run.

What you should see

The whole game. E on the beach: The shed door is nailed shut against the weather. With the crowbar: OPEN DOOR WITH CROWBAR, You lever the door open with the crowbar. The nails shriek and give., and the shed is open. Find the rest yourself; Appendix II has a solution. Lighting the great lamp ends the game, back at Turbo's >.

Change One Thing

  • In Start, change the matches' place from -1 to 7. What do you see in the kitchen, before opening anything?
  • In Walk, change not (Lit and Carried(2)) to not Lit. Light the lantern on the stairs, drop it, and go up. Should you be able to?
  • In Open, change (N2 = 20) and Carried(1) to (N2 = 25) and Carried(6). What opens the shed now?

Exercises

20.1 On the stairs, once the lantern is lit and carried, add a line to the description: Your lantern lights the way up.

20.2 LIGHT MATCHES should not say You can't light that.: make it say A match flares and dies.

20.3 Turn XYZZY into a hint: a different line depending on which puzzle comes next.

Worked solutions are in Appendix II.

Summary

A puzzle is a flag: set by one action, tested by another. Hidden things have the place -1 until they are found. Sentences with two nouns let Open check what it is being opened with. Every word the game says comes from BEACON.MSG by number.

Next

S21, The Finished Game: a title, an ending, and a game that runs without Turbo.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.