-
Notifications
You must be signed in to change notification settings - Fork 0
/
Person.rb
55 lines (48 loc) · 1.07 KB
/
Person.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
class Person < Creature
@@group = []
def self.group
@@group.compact
end
def self.group=(new_group)
@@group = new_group
end
def self.total
@@group.compact.size
end
attr_accessor :dog, :attacking_zombies, :weapon
def initialize(name = nil, posx = nil, posy = nil)
super
@name = name || "Persona #{@@group.size+1}"
@dog, @weapon = nil, nil
@attacking_zombies = 0
@@group << self
end
def to_s
"#{@name} --> (#{@x}, #{@y})"
end
def danger?(zombie)
if close_to? zombie
puts " : ¡Cuidado! ¡#{zombie.name} está cerca!"
return true
else
return false
end
end
def zombified_by(zombie)
puts " : Has sido convertido en zombie por #{zombie.name}"
@@group[@@group.index(self)] = nil
end
def meet?(dog)
if @dog.nil? && dog.owner.nil? && beside?(dog)
@dog = dog
dog.owner = self
puts " : Has adoptado a #{@dog.name}"
end
end
def found?(weapon)
if @weappon.nil? && over?(weapon)
@weapon = weapon
puts " : Has encontrado un arma"
end
end
end