-
Notifications
You must be signed in to change notification settings - Fork 0
/
pokemon.rb
executable file
·62 lines (49 loc) · 1.3 KB
/
pokemon.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
require_relative 'type_bonification'
class Pokemon
attr_reader :physical_attack, :physical_defense,
:speed, :type
attr_accessor :current_hp
@@bonificator = TypeBonification.new
def initialize(name, type, hp, physical_attack, physical_defense, speed)
@name = name
@type = type
@max_hp = hp
@current_hp = hp
@physical_attack = physical_attack
@physical_defense = physical_defense
@speed = speed
end
def healthier_than?(other)
@current_hp > other.current_hp
end
def faster_than?(other)
@speed > other.speed
end
def stronger_than?(other)
@physical_attack > other.physical_attack
end
def attack(other)
bonification = @@bonificator.damage_bonification(@type, other.type)
raw_damage = @physical_attack - other.physical_defense * 0.5
damage = (raw_damage * bonification).to_i
# Bonus por vida restante
if ((@current_hp % 2).zero? || (@current_hp % 5).zero?) && @current_hp < 25
damage *= 5
elsif @current_hp < 50 || other.healthier_than?(self)
damage *= 3
else
damage += 1
end
# Bonus por desventaja
if bonification <= 1 || (other.faster_than?(self) && @speed > 5)
damage *= 1.5
end
[1, damage].max
end
def alive?
@current_hp.positive?
end
def to_s
@name
end
end