-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharmander.py
More file actions
99 lines (83 loc) · 4.45 KB
/
Copy pathCharmander.py
File metadata and controls
99 lines (83 loc) · 4.45 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
92
93
94
95
96
97
98
99
from Fire import Fire
class Charmander(Fire):
# This class represents objects of Charmander Pokemons.
def __init__(self, name, catch_rate, pokemon_type, level, hit_points, attack_power, defense_power):
Fire.__init__(self, name, catch_rate, pokemon_type)
if not isinstance(level, int): # Validating input type.
raise TypeError("Expected an Integer between 1-15")
if (level < 1) or (level > 15): # Validating input value.
raise ValueError("The Charmander level must be between 1-15")
self._level = level
if not isinstance(hit_points, int): # Validating input type.
raise TypeError("Expected an Integer between 39-57")
if (hit_points < 39) or (hit_points > 57): # Validating input value.
raise ValueError("The Charmander HP must be between 39-57")
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 52-63")
if (attack_power < 52) or (attack_power > 63): # Validating input value.
raise ValueError("The Charmander Attack Power must be between 52-63")
self._attack_power = attack_power
if not isinstance(defense_power, int): # Validating input type.
raise TypeError("Expected an Integer between 43-57")
if (defense_power < 43) or (defense_power > 57): # Validating input value.
raise ValueError("The Charmander Defense Power must be between 43-57")
self._defense_power = defense_power
def __repr__(self):
return "The Charmander " + self.get_name() + " of level " + str(self._level) + " with " + str(self._hit_points) + " HP"
# The method returns the amount of HP of the Charmander.
def get_hit_points(self):
return int(self._hit_points)
# The method returns the defense power of the Charmander.
def get_defense_power(self):
return int(self._defense_power)
# The method return a boolean variable if the Charmander 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 returns the amount of damage (int) that the Charmander 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 Fire 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)
# The method represents an attack of the Charmander 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 updates the level of the Charmander.
def level_up(self, level_gain):
if not isinstance(level_gain, int): # Validating input type.
raise TypeError("Expected an Integer between 1-16")
if (level_gain < 1) and (level_gain > 16): # Validating input value.
self._level = self._level
else: # adding levels to current level.
self._level += level_gain
# checking if Charmander needs to be evolved or not.
if self._level > 15:
return self.evolve()
else:
return None
# The method returns a Charmeleon object, which is an evolved version of the Charmander.
def evolve(self):
from Charmeleon import Charmeleon
hit_points = self._hit_points + 19
if hit_points < 58:
hit_points = 58
attack_power = self._attack_power + 12
defense_power = self._defense_power + 15
new_charmeleon = Charmeleon(self.get_name(), self.get_catch_rate(), self.get_pokemon_type(), self._level, hit_points, attack_power, defense_power)
return new_charmeleon