# \[Solution\] Lisp Game #49

**URL:** <https://rubytalk.org/t/solution-lisp-game-49/21358>\
**Category:** ruby-talk\
**Created:** [6 October 2005 01:41 UTC](https://rubytalk.org/t/solution-lisp-game-49/21358 "2005-10-06T01:41:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_O\_Halpin](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@Sean\_O\_Halpin](https://rubytalk.org/u/Sean_O_Halpin)\
**Post date:** [6 October 2005 01:41 UTC](https://rubytalk.org/t/solution-lisp-game-49/21358/1 "2005-10-06T01:41:44Z")

</div>

I wasn't going to finish this but somehow I couldn't stop myself.... 🙂

It's not tested & debugged but I had to post it before I spent way too  
much time on it.

Now if I can integrate it with IFMapper...

---- CODE ---

#$DEBUG\_GAME = true  
def dbg(\*args)  
&nbsp;&nbsp;puts \*args if $DEBUG\_GAME  
end

class Object  
&nbsp;&nbsp;def in?(container)  
&nbsp;&nbsp;&nbsp;&nbsp;container.include?(self)  
&nbsp;&nbsp;end  
end

module Attributes  
&nbsp;&nbsp;def has(\*names)  
&nbsp;&nbsp;&nbsp;&nbsp;self.class\_eval {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;names.each do |name|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# with args = setter  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# without = getter  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;define\_method(name) {|\*args|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if args.size \> 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance\_variable\_set("@#{name}", \*args)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance\_variable\_get("@#{name}")  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# also define traditional setter=  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;define\_method("#{name}=") {|\*args|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance\_variable\_set("@#{name}", \*args)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;end

end

module Directions  
&nbsp;&nbsp;def directions(\*directions)  
&nbsp;&nbsp;&nbsp;&nbsp;directions.each do |name|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.class.class\_eval {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;define\_method(name) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;go(name)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
end

class GameObject  
&nbsp;&nbsp;extend Attributes  
&nbsp;&nbsp;has :identifier, :name, :description  
&nbsp;&nbsp;def initialize(identifier, &block)  
&nbsp;&nbsp;&nbsp;&nbsp;@identifier = identifier  
&nbsp;&nbsp;&nbsp;&nbsp;instance\_eval &block  
&nbsp;&nbsp;end  
end

class Thing \< GameObject  
&nbsp;&nbsp;has :location, :portable

&nbsp;&nbsp;def initialize(identifier, &block)  
&nbsp;&nbsp;&nbsp;&nbsp;# put defaults before super - they will be overridden in block (if at all)  
&nbsp;&nbsp;&nbsp;&nbsp;# e.g. light, dark, etc.  
&nbsp;&nbsp;&nbsp;&nbsp;@portable = true  
&nbsp;&nbsp;&nbsp;&nbsp;super  
&nbsp;&nbsp;end

end

class Room \< GameObject  
&nbsp;&nbsp;has :exits  
end

class Game  
&nbsp;&nbsp;include Directions

&nbsp;&nbsp;attr\_accessor :name, :rooms, :location, :things

&nbsp;&nbsp;def initialize(name, &block)  
&nbsp;&nbsp;&nbsp;&nbsp;@name = name  
&nbsp;&nbsp;&nbsp;&nbsp;@rooms = {}  
&nbsp;&nbsp;&nbsp;&nbsp;@things = {}

&nbsp;&nbsp;&nbsp;&nbsp;# read game definition  
&nbsp;&nbsp;&nbsp;&nbsp;instance\_eval &block

&nbsp;&nbsp;end

&nbsp;&nbsp;def room(identifier, &block)  
&nbsp;&nbsp;&nbsp;&nbsp;@rooms[symbol(identifier)] = Room.new(symbol(identifier), &block)  
&nbsp;&nbsp;end

&nbsp;&nbsp;def thing(identifier, &block)  
&nbsp;&nbsp;&nbsp;&nbsp;@things[symbol(identifier)] = Thing.new(symbol(identifier), &block)  
&nbsp;&nbsp;end

&nbsp;&nbsp;def match\_thing(\*identifiers)  
&nbsp;&nbsp;&nbsp;&nbsp;thing = nil  
&nbsp;&nbsp;&nbsp;&nbsp;identifiers.each do |identifier|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if thing = @things[identifier]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;thing  
&nbsp;&nbsp;end

&nbsp;&nbsp;def symbol(s)  
&nbsp;&nbsp;&nbsp;&nbsp;s.to\_s.to\_sym  
&nbsp;&nbsp;end

&nbsp;&nbsp;def start(room\_identifier)  
&nbsp;&nbsp;&nbsp;&nbsp;@location = @rooms[room\_identifier]  
&nbsp;&nbsp;end

&nbsp;&nbsp;def display\_list(things)  
&nbsp;&nbsp;&nbsp;&nbsp;if things.size \> 2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;things[0..-2].join(", ") + " and " + things[-1]  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;things.join(" and ")  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end

&nbsp;&nbsp;def describe\_path(direction, path)  
&nbsp;&nbsp;&nbsp;&nbsp;"a #{path} going #{direction}"  
&nbsp;&nbsp;end

&nbsp;&nbsp;def describe\_exits(location)  
&nbsp;&nbsp;&nbsp;&nbsp;"There is " + display\_list(location.exits.map {|direction, (path,  
destination)|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;describe\_path(direction, path)  
&nbsp;&nbsp;&nbsp;&nbsp;}) + "."  
&nbsp;&nbsp;end

&nbsp;&nbsp;def describe\_floor(location)  
&nbsp;&nbsp;&nbsp;&nbsp;things = @things.select{|key, thing| thing.location == location.identifier}  
&nbsp;&nbsp;&nbsp;&nbsp;if things.size \> 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"You can also see " + display\_list(things.map{|key, thing| "a  
#{[thing.name](http://thing.name)}"}) + "."  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;""  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end

&nbsp;&nbsp;def main\_loop  
&nbsp;&nbsp;&nbsp;&nbsp;print "\> "  
&nbsp;&nbsp;&nbsp;&nbsp;while input = gets  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;input.chomp!  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case input  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when 'exit', 'quit'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when 'help'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Sorry pal! You're on your own here :)"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#puts "#{input}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tokens = input.split  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd = tokens[0]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rest = tokens[1..-1].map{|x| x.to\_sym}.reject{|x| [x.in](http://x.in)?  
[:the, :to, :on, :in, :a, :with]}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance\_eval { send(cmd, \*rest) }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rescue Exception =\> e  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dbg e.to\_s  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Eh?"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print "\> "  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end

&nbsp;&nbsp;# commands taking symbols

&nbsp;&nbsp;def in\_location(location\_id, thing\_id)  
&nbsp;&nbsp;&nbsp;&nbsp;@things[thing\_id].location == location\_id  
&nbsp;&nbsp;end

&nbsp;&nbsp;def is\_here(thing\_id)  
&nbsp;&nbsp;&nbsp;&nbsp;in\_location(@location.identifier, thing\_id)  
&nbsp;&nbsp;end

&nbsp;&nbsp;def player\_has(thing\_id)  
&nbsp;&nbsp;&nbsp;&nbsp;in\_location(:player, thing\_id)  
&nbsp;&nbsp;end

&nbsp;&nbsp;def player\_in(location\_id)  
&nbsp;&nbsp;&nbsp;&nbsp;@location.identifier == location\_id  
&nbsp;&nbsp;end

&nbsp;&nbsp;def move\_to(location\_id, thing\_id)  
&nbsp;&nbsp;&nbsp;&nbsp;@things[thing\_id].location = location\_id  
&nbsp;&nbsp;end

&nbsp;&nbsp;def move\_here(thing\_id)  
&nbsp;&nbsp;&nbsp;&nbsp;move\_to(@location.identifier, thing\_id)  
&nbsp;&nbsp;end

&nbsp;&nbsp;def destroy(thing\_id)  
&nbsp;&nbsp;&nbsp;&nbsp;move\_to(:nowhere, thing\_id)  
&nbsp;&nbsp;end

&nbsp;&nbsp;def pick\_up(thing\_id)  
&nbsp;&nbsp;&nbsp;&nbsp;move\_to(:player, thing\_id)  
&nbsp;&nbsp;end

&nbsp;&nbsp;# verbs

&nbsp;&nbsp;def look  
&nbsp;&nbsp;&nbsp;&nbsp;puts location.description  
&nbsp;&nbsp;&nbsp;&nbsp;puts describe\_exits(location)  
&nbsp;&nbsp;&nbsp;&nbsp;puts describe\_floor(location)  
&nbsp;&nbsp;end

&nbsp;&nbsp;def go(direction)  
&nbsp;&nbsp;&nbsp;&nbsp;dest = @location.exits[direction]  
&nbsp;&nbsp;&nbsp;&nbsp;if dest  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@location = @rooms[dest[1]]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;look  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "You can't move in that direction"  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
&nbsp;&nbsp;alias :walk :go

&nbsp;&nbsp;def inventory  
&nbsp;&nbsp;&nbsp;&nbsp;carried = @things.select{|key, thing| player\_has(thing.identifier)}  
&nbsp;&nbsp;&nbsp;&nbsp;puts "You are carrying " +  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if carried.size \> 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"a #{display\_list(carried.map{|key, thing| [thing.name](http://thing.name)})}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"nothing"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
&nbsp;&nbsp;alias :i :inventory

&nbsp;&nbsp;def get(\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;if thing = match\_thing(\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if is\_here(thing.identifier)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if thing.portable  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pick\_up(thing.identifier)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "OK - you picked up the #{[thing.name](http://thing.name)}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "You try and you try but you just can't pick up the  
#{[thing.name](http://thing.name)}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "You can't see a #{[thing.name](http://thing.name)} here"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Get what?"  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
&nbsp;&nbsp;alias :take :get

&nbsp;&nbsp;def drop(\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;if thing = match\_thing(\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if player\_has(thing.identifier)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;move\_here(thing.identifier)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "OK - you dropped the #{[thing.name](http://thing.name)}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"You're not carrying a #{[thing.name](http://thing.name)}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Drop what?"  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end

&nbsp;&nbsp;def examine(\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;if obj = match\_thing(\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if is\_here(obj.identifier)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Looks like #{obj.description}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "You can't see that here"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Don't know what you're talking about"  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
&nbsp;&nbsp;alias :exam :examine

end

def game(name, &block)  
&nbsp;&nbsp;puts "Welcome to #{name}\n\n"  
&nbsp;&nbsp;g = Game.new(name, &block)  
&nbsp;&nbsp;g.look  
&nbsp;&nbsp;g.main\_loop  
end

# Game definition

game "Ruby Adventure" do

&nbsp;&nbsp;directions :east, :west, :north, :south, :upstairs, :downstairs  
&nbsp;&nbsp;alias :up :upstairs  
&nbsp;&nbsp;alias :down :downstairs

&nbsp;&nbsp;# rooms

&nbsp;&nbsp;room :living\_room do  
&nbsp;&nbsp;&nbsp;&nbsp;name 'Living Room'  
&nbsp;&nbsp;&nbsp;&nbsp;description "You are in the living-room of a wizard's house. There  
is a wizard snoring loudly on the couch."  
&nbsp;&nbsp;&nbsp;&nbsp;exits :west =\> [:door, :garden],  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:upstairs =\> [:stairway, :attic]  
&nbsp;&nbsp;end

&nbsp;&nbsp;room :garden do  
&nbsp;&nbsp;&nbsp;&nbsp;name 'Garden'  
&nbsp;&nbsp;&nbsp;&nbsp;description "You are in a beautiful garden. There is a well in  
front of you."  
&nbsp;&nbsp;&nbsp;&nbsp;exits :east =\> [:door, :living\_room]  
&nbsp;&nbsp;end

&nbsp;&nbsp;room :attic do  
&nbsp;&nbsp;&nbsp;&nbsp;name "Attic"  
&nbsp;&nbsp;&nbsp;&nbsp;description "You are in the attic of the wizard's house. There is  
a giant welding torch in the corner."  
&nbsp;&nbsp;&nbsp;&nbsp;exits :downstairs =\> [:stairway, :living\_room]  
&nbsp;&nbsp;end

&nbsp;&nbsp;start :living\_room

&nbsp;&nbsp;# things

&nbsp;&nbsp;thing :wizard do  
&nbsp;&nbsp;&nbsp;&nbsp;name "wizard"  
&nbsp;&nbsp;&nbsp;&nbsp;description "a typical wizard - pointy hat, wand, unkempt beard,  
smelly feet"  
&nbsp;&nbsp;&nbsp;&nbsp;location :living\_room  
&nbsp;&nbsp;&nbsp;&nbsp;portable false  
&nbsp;&nbsp;end

&nbsp;&nbsp;thing :self do  
&nbsp;&nbsp;&nbsp;&nbsp;name "Yourself"  
&nbsp;&nbsp;&nbsp;&nbsp;description "your same ol' ugly self"  
&nbsp;&nbsp;&nbsp;&nbsp;portable false  
&nbsp;&nbsp;end

&nbsp;&nbsp;thing :bottle do  
&nbsp;&nbsp;&nbsp;&nbsp;name 'whiskey bottle'  
&nbsp;&nbsp;&nbsp;&nbsp;description 'a half-empty whiskey bottle'  
&nbsp;&nbsp;&nbsp;&nbsp;location :living\_room  
&nbsp;&nbsp;end

&nbsp;&nbsp;thing :bucket do  
&nbsp;&nbsp;&nbsp;&nbsp;name 'bucket'  
&nbsp;&nbsp;&nbsp;&nbsp;description 'a rusty bucket'  
&nbsp;&nbsp;&nbsp;&nbsp;location :living\_room  
&nbsp;&nbsp;end

&nbsp;&nbsp;thing :welded\_bucket do  
&nbsp;&nbsp;&nbsp;&nbsp;name "bucket"  
&nbsp;&nbsp;&nbsp;&nbsp;description "a bucket with a chain welded to it"  
&nbsp;&nbsp;&nbsp;&nbsp;location :nowhere  
&nbsp;&nbsp;end

&nbsp;&nbsp;thing :filled\_bucket do  
&nbsp;&nbsp;&nbsp;&nbsp;name "bucket"  
&nbsp;&nbsp;&nbsp;&nbsp;description "a bucket full of water with a chain welded to it"  
&nbsp;&nbsp;&nbsp;&nbsp;location :nowhere  
&nbsp;&nbsp;end

&nbsp;&nbsp;# chain  
&nbsp;&nbsp;thing :chain do  
&nbsp;&nbsp;&nbsp;&nbsp;name 'chain'  
&nbsp;&nbsp;&nbsp;&nbsp;description 'a sturdy iron chain'  
&nbsp;&nbsp;&nbsp;&nbsp;location :garden  
&nbsp;&nbsp;end

&nbsp;&nbsp;thing :frog do  
&nbsp;&nbsp;&nbsp;&nbsp;name 'frog'  
&nbsp;&nbsp;&nbsp;&nbsp;description 'a wide-mouthed frog'  
&nbsp;&nbsp;&nbsp;&nbsp;location :garden  
&nbsp;&nbsp;end

&nbsp;&nbsp;# verbs

&nbsp;&nbsp;def splash(\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;thing, \*rest = \*args  
&nbsp;&nbsp;&nbsp;&nbsp;if thing == :wizard and player\_in(:living\_room) and  
player\_has(:filled\_bucket)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if player\_has(:frog)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "The wizard awakens and sees that you stole his frog. He  
is so upset he banishes you to the netherworlds - you lose! The end."  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "The wizard awakens from his slumber and greets you  
warmly. He hands you the magic low-carb donut - you win! The end."  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;elsif thing == :bucket  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "The bucket has nothing in it"  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "With what?"  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end

&nbsp;&nbsp;def attach(\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;subject, object, \*rest = \*args  
&nbsp;&nbsp;&nbsp;&nbsp;if [subject, object].in?([[:chain, :bucket], [:bucket, :chain]])  
and player\_in(:attic) and player\_has(:bucket) and player\_has(:chain)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destroy(:bucket)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destroy(:chain)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pick\_up(:welded\_bucket)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "The chain is now securely welded to the bucket."  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Interesting..."  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
&nbsp;&nbsp;alias :weld :attach

&nbsp;&nbsp;def fill(\*args)  
&nbsp;&nbsp;&nbsp;&nbsp;thing, \*rest = \*args  
&nbsp;&nbsp;&nbsp;&nbsp;if thing == :bucket and player\_in(:garden) and player\_has(:welded\_bucket)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destroy(:welded\_bucket)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pick\_up(:filled\_bucket)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "You have filled the bucket with water"  
&nbsp;&nbsp;&nbsp;&nbsp;elsif thing == :bucket  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if player\_in(:garden)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "You can't reach the water in the well. You'll need  
something to lower the bucket down"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif player\_has(:bucket)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Fill it with what?"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "You don't have the bucket!"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Hmmmm...."  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
&nbsp;&nbsp;alias :dunk :fill

end

\_\_END\_\_  
get bucket  
go west  
get chain  
east  
upstairs  
weld chain to bucket  
down  
west  
fill bucket  
east  
splash wizard

--- END CODE ---

Regards,

Sean
