Class: Portal

Inherits:
Thing
  • Object
show all
Defined in:
lib/gamefic-standard/entities/portal.rb

Direct Known Subclasses

Door

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#destinationGamefic::Entity

Returns:



3
4
5
# File 'lib/gamefic-standard/entities/portal.rb', line 3

def destination
  @destination
end

#directionDirection?

Get the ordinal direction of this Portal Portals have distinct direction and name properties so games can display a bare compass direction for exits, e.g., “south” vs. “the southern door.”

A portal’s destination can also be nil, in which case it can be referenced in commands by its destination, e.g., “go to the house.”

Returns:



13
14
15
# File 'lib/gamefic-standard/entities/portal.rb', line 13

def direction
  @direction
end

Instance Method Details

#instructionObject



34
35
36
# File 'lib/gamefic-standard/entities/portal.rb', line 34

def instruction
  direction || (destination ? "to #{destination.definitely}" : name)
end

#nameObject



30
31
32
# File 'lib/gamefic-standard/entities/portal.rb', line 30

def name
  @name || (direction.nil? ? destination.name : direction.name)
end

#reverseRoom? Also known as: find_reverse

Find the portal in the destination that returns to this portal’s parent

Returns:



18
19
20
21
22
23
# File 'lib/gamefic-standard/entities/portal.rb', line 18

def reverse
  return nil if destination.nil?
  destination.children.that_are(Portal).find do |portal|
    portal.destination == parent
  end
end

#synonymsObject



38
39
40
# File 'lib/gamefic-standard/entities/portal.rb', line 38

def synonyms
  "#{super} #{@destination} #{@direction} #{!direction.nil? ? direction.synonyms : ''}"
end