Class: Degica::Room

Inherits:
Object
  • Object
show all
Includes:
Actionable
Defined in:
lib/degica/room.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Actionable

#do, #prompt

Constructor Details

#initialize(description, objects = []) ⇒ Room

Returns a new instance of Room.



6
7
8
9
10
11
# File 'lib/degica/room.rb', line 6

def initialize(description, objects = [])
  @description = description.highlight
  @doors = DoorCollection.new
  @objects = ObjectCollection.new(objects)
  @generated = false
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/degica/room.rb', line 4

def description
  @description
end

#doorsObject

Returns the value of attribute doors.



4
5
6
# File 'lib/degica/room.rb', line 4

def doors
  @doors
end

Instance Method Details

#actionsObject



24
25
26
27
28
29
# File 'lib/degica/room.rb', line 24

def actions
  actions = @doors.actions + @objects.actions
  actions << Action.new(:room, self)
  actions << Action.new(:door, @doors.first) if @doors.size == 1
  actions
end

#describeObject



31
32
33
# File 'lib/degica/room.rb', line 31

def describe
  @description
end

#generate!Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/degica/room.rb', line 13

def generate!
  return if @generated
  @generated = true

  rooms = Game.objects.rooms.select do |room|
    room.doors.empty? && room != self
  end.sample(rand(1..2))

  rooms.map { |r| make_door(r) }
end