🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.programmer
Article #757

text adventure source

#757
From: Ryan Williams
Date: Mon, 17 Aug 1992 07:45
221 lines
3163 bytes
I was able to come up with a template for a text adventure. It's pretty
simple, only being a square 10 x 10 grid to move about. Have fun: 
 
 program Dungeon;

uses Dos, Crt;

var

   Room     : array[1..100] of String[80];

   YourName : String[20];

   CuRoom   : integer;

   Score    : integer;

   Tk       : string[80];

   DUff     : boolean;

 

procedure LoadData;

var

   DirInfo  : SearchRec;

   FileName : string[12];

   FileData : text;

   Cycle    : byte;

   Duh      : string[80];

 

begin

 CuRoom:=1;

 FindFirst('ROOMS.DAT',Archive,DirInfo);

 if DosError<>0 then begin

                      Writeln('ROOMS.DAT file not found.');

                     End;

 assign(FileData,'ROOMS.DAT');

 reset(FileData);

 repeat

  Readln(FileData,Room[CuRoom]);

  Inc(CURoom);

 until CuRoom=101;

End;

 

procedure North;

begin

 if CuRoom<11 then begin

                    Writeln('You can''t go that way.');

                   End;

 if CuRoom>10 then begin

                    CuRoom:=CuRoom-10;

                   End;

End;

 

procedure South;

begin

 if CuRoom>90 then begin

                    Writeln('You can''t go that way.');

                   End;

 if CuRoom<91 then begin

                    CuRoom:=CuRoom+10;

                   End;

End;

 

procedure East;

begin

 case CuRoom of

  10,20,30,40,50,60,70,80,90,100 : begin

                                    Writeln('You can''t go that way.');

                                    Exit;

                                   End;

  End;

  Inc(CuRoom);

End;

 

procedure West;

begin

 case CuRoom of

  1,11,21,31,41,51,61,71,81,91 : begin

                                  Writeln('You can''t go that way.');

                                  Exit;

                                 End;

 End;

 Dec(CuRoom);

End;

 

 

procedure GetCmd;

 

var

   J : integer;

 

begin

 Writeln('You are in ',Room[CuRoom]);

 Writeln('Room number: ',CuRoom);

 repeat

  Write(' >');

  Readln(Tk);

  for J:=1 to Length(Tk) do

   Tk[J]:=upcase(Tk[J]);

 until not(Tk='');

 if Tk='N' then North;

 if Tk='S' then South;

 if Tk='E' then East;

 if Tk='W' then West;

End;

 

begin

LoadData;

CuRoom:=45;

repeat

 GetCmd;

until Duff=FALSE;

end.

 

 

 

 

 ok. You need to make a file called ROOMS.DAT which will be your room names.
On each its own line, make 100 rooms up. Simple as that. 
 Room #1 will be the top left corner, #10 being the top right, #90 being
bottom left, and 100 being bottom right. Hope the program works. I wrote it
using Turbo Pascal version 4. 
 Have fun.
Technical Details
Message-ID: <8263@orbit.cts.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!purdue!news.cs.indiana.edu!umn.edu!kksys.com!orbit!pnet51!dt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!purdue!news.cs.indiana.edu!umn.edu!kksys.com!orbit!pnet51!dt
From: dt@pnet51.orb.mn.org (Ryan Williams)
Newsgroups: rec.games.programmer
Subject: text adventure source
Message-ID: <8263@orbit.cts.com>
Date: 17 Aug 92 07:45:01 GMT
Sender: news@orbit.cts.com
Organization: People-Net [pnet51], Minneapolis, MN.
Lines: 221