PASCAL\ADVENT_2.PAS  ·  PAS  ·  4.4 KB  ·  1988-03-22  ·  from PCPlus_Issue-20_May-1988
program advent_2; 

const
     NumOfRooms = 9;
     Way = 'Which way do you want to go? (N/S/E/W)';
     NoWay = 'You cannot move in that direction.';
     WhichWay = 'There are exits... ';
     NoGo = 'That is not a valid response.';
     OKWay = 'You have moved in that direction.';

type
    Room = array[1..4] of integer;

var
   SunnyRoom, Entrance, Garden, Study, Kitchen, Passage, DiningRoom : Room;
   Patio, Cupboard : Room;
   ThisRoom : Room;
   RoomNum : integer;
   Move : char;
   Dir : integer;

procedure describe;      {Sets up descriptions for all rooms}
     begin
          write('You are in ');
          case RoomNum of
             1:      writeln('a pleasant, sunny room.');
             2:      writeln('a dark entrance hall.');
             3:      writeln('a garden full of trees and flowers.');
             4:      writeln('a book-lined study.');
             5:      writeln('a kitchen full of dirty dishes.');
             6:      writeln('a passage lined with locked doors.');
             7:      writeln('a dining room, with the remains of a meal.');
             8:      writeln('a walled patio, full of flowers.');
             9:      writeln('a dark cupboard, smelling of must and decay.')

          end;
     end;

procedure Exits;
   begin
   write(WhichWay);
     for Dir := 1 to 4 do
         if ThisRoom[Dir] <> 0 then
           Case Dir of
             1: write('north ');
             2: write('south ');
             3: write('east ');
             4: write('west ');
           end;
   writeln('.');
   end;

procedure CheckMove;     {Handles movement}
   begin
    if ord(Move) > 97 then Move := chr(ord(Move)-32); {Changes L Case to Caps}
    if (Move<>'N') and (Move<>'S') and (Move<>'E') and (Move<>'W') then
        begin
        writeln(NoGo);   {Blocks illegal direction for move}
        DIR := 0;
        end
     else
         begin
         case Move of
         'N' : Dir := 1;
         'S' : Dir := 2;
         'E' : Dir := 3;
         'W' : Dir := 4;
         end;

         case ThisRoom[Dir] of
         0:   writeln(NoWay);  {Message for no exit}
         1,2,3,4,5,6,7 :
                       begin
                       writeln(OKWay);            {Allows move}
                       RoomNum := ThisRoom[Dir];  {Changes to new room number}
                       end;
         end;
       end;
   end;


procedure SetRooms;   {Set up the exits from the rooms}

var
        ThisRoom : Room;
        I, J : integer;
        Exits : string;

begin

        Exits := '042005310002160027004970508600076000';
        for I:= 1 to 9 do
          begin
            for J:= 1 to 4 do
              begin
              ThisRoom[J]:= Ord(Exits[(I-1)*4+J])-48;
                case I of
                1:    SunnyRoom[J]:= ThisRoom[J];
                2:    Entrance[J]:= ThisRoom[J];
                3:    Garden[J]:= ThisRoom[J];
                4:    Study[J]:= ThisRoom[J];
                5:    Kitchen[J]:= ThisRoom[J];
                6:    Passage[J]:= ThisRoom[J];
                7:    DiningRoom[J]:= ThisRoom[J];
                8:    Patio[J]:= ThisRoom[J];
                9:    Cupboard[J]:= ThisRoom[J]
                end;
            end;
          end;
end;

procedure NewRoom (var New : Room);  {Locates player in correct room}

var
    J: integer;

begin
        For J:= 1 to 4 do
      begin
        Case RoomNum of
        1:      New[J]:= SunnyRoom[J];
        2:      New[J]:= Entrance[J];
        3:      New[J]:= Garden[J];
        4:      New[J]:= Study[J];
        5:      New[J]:= Kitchen[J];
        6:      New[J]:= Passage[J];
        7:      New[J]:= DiningRoom[J];
        8:      New[J]:= Patio[J];
        9:      New[J]:= Cupboard[J];
        end;
      end;
end;

begin
     SetRooms;                    {Set up room exits}
     RoomNum := 5;                {Set room number}
     NewRoom(ThisRoom);           {Place player in room}
     Describe;                    {Describe current room}
     Exits;                       {List exits}
     writeln(Way);                {Invite input}
     readln(Move);                {Read input}
     CheckMove;                   {Check input & respond accordingly}
     NewRoom(ThisRoom);           {Place player in room}
     Describe                     {Describe current room};
end.