home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LANGUAGE / ADA / LOVELACE / rooms.adb < prev    next >
Text File  |  1996-03-01  |  2KB  |  63 lines

  1. --
  2. -- Copyright (C) 1996 Ada Resource Association (ARA), Columbus, Ohio.
  3. -- Author: David A. Wheeler
  4. --
  5.  
  6. with Text_IO, Ustrings;
  7. use  Text_IO, Ustrings;
  8.  
  9. package body Rooms is
  10.  
  11.  procedure Connect(Source : access Room; Dir : in Direction; 
  12.                    Destination : access Thing'Class;
  13.                    Bidirectional : in Boolean := True) is
  14.  begin
  15.    Source.Destinations(Dir) := Thing_Access(Destination);
  16.    if Bidirectional then  -- Connect in reverse direction.
  17.      Room_Access(Destination).Destinations(Reverse_Direction(Dir)) := 
  18.               Thing_Access(Source);
  19.    end if;
  20.  end Connect;
  21.  
  22.  procedure Disconnect(Source : access Room; Dir : in Direction; 
  23.                       Bidirectional : in Boolean := True) is
  24.  begin
  25.    if Bidirectional then
  26.      -- If it's bidirectional, remove the other direction. The following "if"
  27.      -- statement, if uncommented, checks to make sure that
  28.      -- disconnecting a bidirectional link only happens to a Room.
  29.      -- if (Source.Destinations(Dir).all'Tag in Room'Class) then
  30.        Room_Access(Source.Destinations(Dir)).
  31.                    Destinations(Reverse_Direction(Dir)) := null;
  32.      -- end if;
  33.    end if;
  34.    Source.Destinations(Dir) := null;
  35.  end Disconnect;
  36.  
  37.  function What_Is(From : access Room; Dir : in Direction) return Thing_Access is
  38.  begin
  39.   return From.Destinations(Dir);
  40.  end What_Is;
  41.  
  42.  procedure Put_View(T : access Room; Agent : access Thing'Class) is
  43.  begin
  44.   Put("You are ");
  45.   Put(Long_Description(T));
  46.   Put_Line(".");
  47.   Put_Contents(T, Agent, "You see:");
  48.  end Put_View;
  49.  
  50. end Rooms;
  51.  
  52. --
  53. -- Permission to use, copy, modify, and distribute this software and its
  54. -- documentation for any purpose and without fee is hereby granted,
  55. -- provided that the above copyright and authorship notice appear in all
  56. -- copies and that both that copyright notice and this permission notice
  57. -- appear in supporting documentation.
  58. -- 
  59. -- The ARA makes no representations about the suitability of this software
  60. -- for any purpose.  It is provided "as is" without express
  61. -- or implied warranty.
  62. -- 
  63.