home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / docs / lovelace / occupant.adb < prev    next >
Encoding:
Text File  |  1995-11-01  |  2.0 KB  |  85 lines

  1.  
  2. with Text_IO, Ada.Strings.Unbounded, Ustrings, Rooms;
  3. use  Text_IO, Ada.Strings.Unbounded, Ustrings, Rooms;
  4.  
  5. package body Occupants is
  6.  
  7.  
  8.  procedure Put_View(T : access Occupant; Agent : access Thing'Class) is
  9.  begin
  10.   Put("You are inside ");
  11.   Put_Line(Short_Description(T));
  12.   Put_Line(".");
  13.   Put_Contents(T, Agent, "You see:");
  14.  end Put_View;
  15.  
  16.  procedure Look(T : access Occupant) is
  17.  -- T is running a "look" command; tell T what he views.
  18.  begin
  19.   if Container(T) = null then
  20.     Put("You are inside nothing at all.");
  21.   else
  22.     Put_View(Container(T), T);
  23.   end if;
  24.  end Look;
  25.  
  26.  
  27.  procedure Get(Agent : access Occupant; Direct_Object : access Occupant'Class)
  28.  is
  29.  begin
  30.    if May_I_Get(Direct_Object, Agent) then
  31.      Place(T => Direct_Object, Into => Thing_Access(Agent));
  32.    end if;
  33.  end Get;
  34.  
  35.  function May_I_Get(Direct_Object : access Occupant;
  36.                     Agent : access Occupant'Class)
  37.           return Boolean is
  38.  begin
  39.    Sorry("get", Name(Direct_Object));  -- Tell the getter sorry, can't get it
  40.    return False;
  41.  end May_I_Get;
  42.  
  43.  procedure Drop(Agent : access Occupant;
  44.                 Direct_Object : access Occupant'Class) is
  45.  begin
  46.    if May_I_Drop(Direct_Object, Agent) then
  47.      Place(T => Direct_Object, Into => Container(Agent));
  48.    end if;
  49.  end Drop;
  50.  
  51.  function  May_I_Drop(Direct_Object : access Occupant;
  52.                       Agent : access Occupant'Class)
  53.            return Boolean is
  54.  begin
  55.    return True;
  56.  end May_I_Drop;
  57.  
  58.  
  59.  procedure Inventory(Agent : access Occupant) is
  60.  begin
  61.   Put_Contents(Agent, Agent,
  62.                "You're carrying:",
  63.                "You aren't carrying anything.");
  64.  end Inventory;
  65.  
  66.  procedure Go(Agent : access Occupant; Dir : in Direction) is
  67.  begin
  68.   if Container(Agent) = null then
  69.     Put_Line("Sorry, you're not in a room!");
  70.   else
  71.     declare
  72.       Destination : Thing_Access := What_Is(Container(Agent), Dir);
  73.     begin
  74.      if Destination = null then
  75.        Put_Line("Sorry, you can't go that way.");
  76.      else
  77.        Place(Agent, Destination);
  78.      end if;
  79.     end;
  80.   end if;
  81.  end Go;
  82.  
  83. end Occupants;
  84.  
  85.