lib/t10/dungeon/traversable.rb
def add_door_leading_to(room)
        if @doors.find { |_, v| v[-1].class == room.class }
          fail StandardError, "Duplicate rooms not allowed!"
        end

        left_crest  = get_crest_from_relative(:to_left) if @has_left
        right_crest = get_crest_from_relative(:to_right) if @has_right
        ahead_crest = get_crest_from_relative(:ahead) if @has_ahead

        case
        # does the room have a door to the left and is that door not occupied?
        when @has_left && @doors[left_crest][-1].nil?
          @doors[left_crest][-1] = room
          left_crest
        when @has_right && @doors[right_crest][-1].nil?
          @doors[right_crest][-1] = room
          right_crest
        when @has_ahead && @doors[ahead_crest][-1].nil?
          @doors[ahead_crest][-1] = room
          ahead_crest
        else
          fail StandardError,
               "All doors for room #{self.class} occupied." \
               " #{room.class} not added."
        end
      end
# This method adds the room (parameter) to the @doors of the receiver
# (origin room). This method is called by the {Traversable#connect_to}.
#
# This method does not handle exceptions, it requires client to know
# the total number of available doors and the number of occupied doors by
# checking the subclass DOORS constant.
#
# After adding the method in the free slot of the @doors determined by the
# @has_left, @has_right and @has_ahead (as well as the DOORS constant) of
# the Room, the method returns the crest (or external orientation) of the
# door that leads to the room (parameter).
#
# @param room [Room] A room to be added to @doors of the origin_room.
# @raise [StandardError] if there are more than one room of the same class.
# @raise [StandardError] if all doors are occupied.
# @return [Symbol] The crest of the door leading to room (parameter)
This method adds the room (parameter) to the @doors of the receiver
(origin room). This method is called by the {Traversable#connect_to}.

This method does not handle exceptions, it requires client to know
the total number of available doors and the number of occupied doors by
checking the subclass DOORS constant.

After adding the method in the free slot of the @doors determined by the
This method adds the room ( parameter ) to the @doors of the receiver ( origin room ) . This method is called by the { Traversable#connect_to } . This method does not handle exceptions it requires client to know the total number of available doors and the number of occupied doors by checking the subclass DOORS constant . After adding the method in the free slot of the @doors determined by the
def add_door_leading_to(room)
        if @doors.find { |_, v| v[-1].class == room.class }
          fail StandardError, "Duplicate rooms not allowed!"
        end
        left_crest  = get_crest_from_relative(:to_left) if @has_left
        right_crest = get_crest_from_relative(:to_right) if @has_right
        ahead_crest = get_crest_from_relative(:ahead) if @has_ahead
        case
        when @has_left && @doors[left_crest][-1].nil?
          @doors[left_crest][-1] = room
          left_crest
        when @has_right && @doors[right_crest][-1].nil?
          @doors[right_crest][-1] = room
          right_crest
        when @has_ahead && @doors[ahead_crest][-1].nil?
          @doors[ahead_crest][-1] = room
          ahead_crest
        else
          fail StandardError,
               "All doors for room #{self.class} occupied." \
               " #{room.class} not added."
        end
      end
def add_door_leading_to ( room ) if @doors . find { | _ , v | v [ - 1 ] . class == room . class } fail StandardError , "Duplicate rooms not allowed!" end left_crest = get_crest_from_relative ( :to_left ) if @has_left right_crest = get_crest_from_relative ( :to_right ) if @has_right ahead_crest = get_crest_from_relative ( :ahead ) if @has_ahead case when @has_left && @doors [ left_crest ] [ - 1 ] . nil? @doors [ left_crest ] [ - 1 ] = room left_crest when @has_right && @doors [ right_crest ] [ - 1 ] . nil? @doors [ right_crest ] [ - 1 ] = room right_crest when @has_ahead && @doors [ ahead_crest ] [ - 1 ] . nil? @doors [ ahead_crest ] [ - 1 ] = room ahead_crest else fail StandardError , "All doors for room #{self.class} occupied." " #{room.class} not added." end end
This method adds the room (parameter) to the @doors of the receiver
(origin room).
This method adds the room ( parameter ) to the @doors of the receiver ( origin room ) .
# does the room have a door to the left and is that door not occupied?
The crest of the door leading to room (parameter)
The crest of the door leading to room ( parameter )
Symbol
[StandardError] if there are more than one room of the same class.
[ StandardError ] if there are more than one room of the same class .
[StandardError] if all doors are occupied.
[ StandardError ] if all doors are occupied .
room
A room to be added to @doors of the origin_room.
A room to be added to @doors of the origin_room .
has_left,
@has_right and @has_ahead (as well as the DOORS constant) of the Room, the method returns the crest (or external orientation) of the door that leads to the room (parameter).
@has_right and @has_ahead ( as well as the DOORS constant ) of the Room the method returns the crest ( or external orientation ) of the door that leads to the room ( parameter ) .