-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPikachu.py
More file actions
91 lines (76 loc) · 4.23 KB
/
Copy pathPikachu.py
File metadata and controls
91 lines (76 loc) · 4.23 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from Electric import Electric
class Pikachu(Electric):
# This class represents objects of Pikachu Pokemons.
def __init__(self, name, catch_rate, pokemon_type, level, hit_points, attack_power, defense_power, friendship):
Electric.__init__(self, name, catch_rate, pokemon_type)
if not isinstance(level, int): # Validating input type.
raise TypeError("Expected an Integer between 1-32")
if (level < 1) or (level > 32): # Validating input value.
raise ValueError("The Pikachu level must be between 1-32")
self._level = level
if not isinstance(hit_points, int): # Validating input type.
raise TypeError("Expected an Integer between 35-99")
if (hit_points < 35) or (hit_points > 99): # Validating input value.
raise ValueError("The Pikachu HP must be between 35-99")
self._hit_points = hit_points
self._original_hp = hit_points
if not isinstance(attack_power, int): # Validating input type.
raise TypeError("Expected an Integer between 55-99")
if (attack_power < 55) or (attack_power > 99): # Validating input value.
raise ValueError("The Pikachu Attack Power must be between 55-99")
self._attack_power = attack_power
if not isinstance(defense_power, int): # Validating input type.
raise TypeError("Expected an Integer between 40-99")
if (defense_power < 40) or (defense_power > 99): # Validating input value.
raise ValueError("The Pikachu Defense Power must be between 40-99")
self._defense_power = defense_power
if not isinstance(friendship, int): # Validating input type.
raise TypeError("Expected an Integer between 1-5")
if (friendship < 1) or (friendship > 5): # Validating input value.
raise ValueError("The Pikachu friendship must be between 1-5")
self._friendship = friendship
def __repr__(self):
return "The Pikachu " + self.get_name() + " of level " + str(self._level) + " with " + str(self._hit_points) + " HP"
# The method returns the amount of HP of the Pikachu.
def get_hit_points(self):
return int(self._hit_points)
# The method returns the defense power of the Pikachu.
def get_defense_power(self):
return int(self._defense_power)
# The method return a boolean variable if the Pikachu can fight.
# it returns True if its HP is higher than 10% of the original HP amount he had in the beginning.
# otherwise, returns False.
def can_fight(self):
if self._hit_points > (self._original_hp // 10):
return True
else:
return False
# The method represents an attack of the Pikachu towards the other Pokemon that was inputted.
# We assume that the input is valid.
def attack(self, other):
if self.can_fight() and other.can_fight():
self._hit_points -= self._original_hp // 10
other.absorb(self.get_damage(other))
# The method updates the HP of the Pokemon after getting attacked.
def absorb(self, damage):
self._hit_points -= damage
# The method returns the amount of damage (int) that the Pikachu can put into the other Pokemon.
# The variable - other, is a Pokemon object. We assume that the input is valid.
def get_damage(self, other):
# The condition checks if the Electric type is in the list of "effective against me" of the other Pokemon.
if self.get_pokemon_type() in other.get_effective_against_me():
eff = 2
else:
eff = 0.5
return int(((((2 * self._level) / 5) + 2) * (self._attack_power / other.get_defense_power()) * eff) + self._friendship)
# The method updates the level of the Pikachu.
def level_up(self, level_gain):
if not isinstance(level_gain, int): # Validating input type.
raise TypeError("Expected a positive Integer")
if level_gain < 0: # Validating input value.
raise ValueError("The variable level_gain must be a positive Integer")
# adding levels to current level.
self._level += level_gain
# A condition that makes sure that the max Pikachu level is 50.
if self._level > 50:
self._level = 50