Skip to content

Commit

Permalink
Create Herbivore and Carnivore subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyHilly committed Oct 22, 2023
1 parent 37e12d6 commit 7aa5d49
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,19 @@ def __repr__(self) -> str:
return (f"{{Name: {self.name}, "
f"Health: {self.health}, "
f"Hidden: {self.hidden}}}")


class Herbivore(Animal):
def hide(self) -> None:
self.hidden = False if self.hidden else True

def bitten(self) -> None:
self.health -= 50
self.is_dead()


class Carnivore(Animal):
def bite(self, other: Herbivore) -> None:
if not isinstance(other, Herbivore) or other.hidden:
return
other.bitten()

0 comments on commit 7aa5d49

Please sign in to comment.