Sha256: 78d894cce6643e487132334bab1c6e4a7c79552f6f6355aa9385191d3cbd3853

Contents?: true

Size: 858 Bytes

Versions: 4

Compression:

Stored size: 858 Bytes

Contents

module Degica
  class Room
    include Actionable
    attr_accessor :description, :doors

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

    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

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

    def describe
      @description
    end

    private

    def make_door(room)
      Door.new(self, room)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
degica-1.0.3 lib/degica/room.rb
degica-1.0.2 lib/degica/room.rb
degica-1.0.1 lib/degica/room.rb
degica-1.0.0 lib/degica/room.rb