-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathmain.py
40 lines (30 loc) · 897 Bytes
/
main.py
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
from __future__ import annotations
class Animal:
alive = []
def __init__(
self,
name: str,
health: int = 100,
hidden: bool = False
) -> None:
self.name = name
self.health = health
self.hidden = hidden
Animal.alive.append(self)
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 = not self.hidden
class Carnivore(Animal):
@staticmethod
def bite(animal: Animal) -> None:
if not animal.hidden and isinstance(animal, Herbivore):
animal.health -= 50
for index, beast in enumerate(Animal.alive):
if beast.health <= 0:
del Animal.alive[index]