Sha256: 40e7096813d325ddc2a7a1457bc1c031d788afd7ba3bf8edabea72c33d1d9eab

Contents?: true

Size: 913 Bytes

Versions: 1

Compression:

Stored size: 913 Bytes

Contents

# @gamefic.script standard/openable

# A module for entities that are openable.
#
module Openable
  def open= bool
    @open = bool
  end

  def open?
    @open ||= false
  end

  def closed?
    !open?
  end

  def accessible?
    open?
  end
end

Gamefic.script do
  respond :open, Use.available do |actor, thing|
    actor.tell "You can't open #{the thing}."
  end

  respond :open, Use.available(Openable) do |actor, thing|
    if thing.open?
      actor.tell "#{The thing} is already open."
    else
      actor.tell "You open #{the thing}."
      thing.open = true
    end
  end

  respond :close, Use.available do |actor, thing|
    actor.tell "You can't close #{the thing}."
  end

  respond :close, Use.available(Openable) do |actor, thing|
    if thing.open?
      actor.tell "You close #{the thing}."
      thing.open = false
    else
      actor.tell "#{The thing} is already open."
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gamefic-standard-2.0.0 lib/gamefic-standard/openable.rb