Sha256: adca3e4bd68109d67f97a916ceb7f9b2a850c8a97cbc459a86e7d5e5b0bf8cbd

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

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

  respond :look, Use.available(Thing, Openable) do |actor, thing|
    actor.proceed
    actor.tell "#{The thing} is #{thing.open? ? 'open' : 'closed'}."
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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