​python_modules /
module-07 / ex1 / _creatures.py
106 commits
21-05-2026
66 lines 2.2 kB
 1from ex0 import Creature
 2from .capabilities import HealCapability, TransformCapability
 3
 4
 5class Sproutling(Creature, HealCapability):
 6    def __init__(self) -> None:
 7        Creature.__init__(self, "Sproutling", "Grass")
 8
 9    def attack(self) -> str:
10        return f"{self._name} uses Vine Whip!"
11
12    def heal(self, target: Creature | None = None) -> str:
13        if target is not None:
14            return f"{self._name} heals {target._name} for a small amount"
15        return f"{self._name} heals itself for a small amount"
16
17
18class Bloomelle(Creature, HealCapability):
19    def __init__(self) -> None:
20        Creature.__init__(self, "Bloomelle", "Grass/Fairy")
21
22    def attack(self) -> str:
23        return f"{self._name} uses Petal Dance!"
24
25    def heal(self, target: Creature | None = None) -> str:
26        if target is not None:
27            return f"{self._name} heals {target._name} for a small amount"
28        return f"{self._name} heals itself and others for a large amount"
29
30
31class Shiftling(Creature, TransformCapability):
32    def __init__(self) -> None:
33        Creature.__init__(self, "Shiftling", "Normal")
34        TransformCapability.__init__(self)
35
36    def attack(self) -> str:
37        if self.transformed:
38            return f"{self._name} performs a boosted strike!"
39        return f"{self._name} attacks normally."
40
41    def transform(self) -> str:
42        self.transformed = True
43        return f"{self._name} shifts into a sharper form!"
44
45    def revert(self) -> str:
46        self.transformed = False
47        return f"{self._name} returns to normal."
48
49
50class Morphagon(Creature, TransformCapability):
51    def __init__(self) -> None:
52        Creature.__init__(self, "Morphagon", "Normal/Dragon")
53        TransformCapability.__init__(self)
54
55    def attack(self) -> str:
56        if self.transformed:
57            return f"{self._name} unleashes a devastating morph strike!"
58        return f"{self._name} attacks normally."
59
60    def transform(self) -> str:
61        self.transformed = True
62        return f"{self._name} morphs into a dragonic battle form!"
63
64    def revert(self) -> str:
65        self.transformed = False
66        return f"{self._name} stabilizes its form."