-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dog.rb
54 lines (48 loc) · 958 Bytes
/
Dog.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
class Dog < 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 :owner
def initialize(name = nil, posx = nil, posy = nil)
super
@name = name || "Perro #{@@group.size+1}"
@owner = nil
@@group << self
end
def walk(step=3)
if @owner
@x = @owner.x
@y = @owner.y
else
super
end
end
def killed_by?(zombie)
if @owner.nil? && beside?(zombie)
puts " #{@name} ha sido asesinado por #{zombie.name}"
@@group[@@group.index(self)] = nil
return true
end
false
end
def attack?(zombie)
if @owner
puts " : #{@name} te ha defendido matando a #{zombie.name}"
puts " : Has dejado de ser dueño de #{@name}"
@owner = nil
return true
else
return false
end
end
def to_s
"¡Guau guau!"
end
end