-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.rb
51 lines (43 loc) · 1.41 KB
/
game.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
require_relative 'Creature.rb'
require_relative 'Person.rb'
require_relative 'Zombie.rb'
require_relative 'Dog.rb'
require_relative 'Weapon.rb'
MAP = [20,20]
Person.group = (1..5).map {|i| Person.new}
Zombie.group = (1..5).map {|i| Zombie.new}
Dog.group = (1...2).map {|i| Dog.new}
Weapon.group = (1..5).map {|i| Gun.new}
# Weapon.group << (1..10).map {|i| Sword.new}
dias = 0
while Person.total > 0 && Zombie.total > 0
dias += 1
puts "Día #{dias}, Personas: #{Person.total}, Zombies: #{Zombie.total}, Perros: #{Dog.total}"
Zombie.group.each(&:walk)
Dog.group.each do |dog|
dog.walk 3
Zombie.group.each { |zombie| break if dog.killed_by?(zombie) }
end
Person.group.each do |person|
puts " #{person}"
person.walk 2
Dog.group.each { |dog| person.meet? dog }
Weapon.group.each { |weapon| person.found? weapon}
zombie_presence, killed, person.attacking_zombies = false, false, 0
Zombie.group.each do |zombie|
killed = zombie.kill? person
break if killed
zombie_presence = true if person.danger? zombie
end
if (!zombie_presence && person.attacking_zombies == 0)
puts " : Todo está tranquilo por aquí"
end
end
#input = gets
puts ''
end
if Person.total == 0
puts "GAME OVER.\n La humanidad ha sido aniquilada en #{dias} días"
else
puts "VICTORY!\n #{Person.total} personas y #{Dog.total} perros han sobrevivido a #{dias} días de epidemia"
end