blob: f81d5099a3cc53a9f28d9ec16ef3205c6e439b80 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
exit 1 if ARGV.empty?
$things = []
$rooms = []
class ThingFactory
def self.create_thing(block)
ThingFactory.new(block).to_thing
end
def initialize(block)
@name = ""
@properties = []
@energy = 0
self.instance_eval(&block)
end
def name(str)
@name = str
end
def property(str, *strs)
@properties << str
@properties += strs
end
def energy(num)
@energy = num
end
def to_thing
return Thing.new(@name, @properties, @energy)
end
end
class Thing
def self.parse(block)
return ThingFactory.create_thing(block)
end
def initialize(name, properties, energy)
@name = name
@properties = properties
@energy = energy
end
def has_property(str)
return @properties.include?(str)
end
def method_missing(name)
if name.to_s =~ /^is_(.*)\?$/ then
has_property($1)
end
end
attr_reader :name
attr_accessor :energy
end
def room(&block)
#return Room.parse(block)
end
def thing(&block)
$things << Thing.parse(block)
end
load ARGV.shift.strip
|