Class: Degica::Door

Inherits:
Object
  • Object
show all
Includes:
Actionable, Collectable
Defined in:
lib/degica/door.rb

Instance Attribute Summary collapse

Attributes included from Collectable

#collection

Instance Method Summary collapse

Methods included from Actionable

#do

Constructor Details

#initialize(room1, room2) ⇒ Door

Returns a new instance of Door.



8
9
10
11
12
13
14
15
# File 'lib/degica/door.rb', line 8

def initialize(room1, room2)
  @description = DoorNameGenerator.sample
  @rooms = [room1, room2]

  # connect rooms
  room1.doors << self
  room2.doors << self
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/degica/door.rb', line 6

def description
  @description
end

Instance Method Details

#actionsObject



17
18
19
# File 'lib/degica/door.rb', line 17

def actions
  [Action.new(:enter, self), Action.new(:open, self)]
end

#describeObject



33
34
35
# File 'lib/degica/door.rb', line 33

def describe
  @description
end

#enterObject



26
27
28
29
30
31
# File 'lib/degica/door.rb', line 26

def enter
  next_room = (@rooms - [Game.objects.actor.location])[0]
  Game.objects.actor.location = next_room
  next_room.generate!
  next_room
end

#openObject



21
22
23
24
# File 'lib/degica/door.rb', line 21

def open
  Game.objects.actor.focus = self
  "You opened the door. Try to (enter) it.".highlight
end

#promptObject



37
38
39
# File 'lib/degica/door.rb', line 37

def prompt
  "door"
end