-
Notifications
You must be signed in to change notification settings - Fork 837
/
space.rb
71 lines (58 loc) · 990 Bytes
/
space.rb
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
module RubyWarrior
class Space
def initialize(floor, x, y)
@floor, @x, @y = floor, x, y
end
def wall?
@floor.out_of_bounds? @x, @y
end
def warrior?
unit.kind_of? Units::Warrior
end
def golem?
unit.kind_of? Units::Golem
end
def player?
warrior? || golem?
end
def enemy?
unit && !player? && !captive?
end
def captive?
unit && unit.bound?
end
def empty?
unit.nil? && !wall?
end
def stairs?
@floor.stairs_location == location
end
def ticking?
unit && unit.abilities.include?(:explode!)
end
def unit
@floor.get(@x, @y)
end
def location
[@x, @y]
end
def character
if unit
unit.character
elsif stairs?
">"
else
" "
end
end
def to_s
if unit
unit.to_s
elsif wall?
"wall"
else
"nothing"
end
end
end
end