-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacter.py
More file actions
35 lines (28 loc) · 872 Bytes
/
Copy pathcharacter.py
File metadata and controls
35 lines (28 loc) · 872 Bytes
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
from abc import ABC, abstractmethod
class Character(ABC):
CountCharacters = 0
def __init__(self, name, health, attack, defense, vitality):
self.name = name
self.health = health
self.attack = attack
self.defense = defense
self.vitality = vitality
Character.CountCharacters += 1
@abstractmethod
def basic_attack(self):
pass
@abstractmethod
def defend(self):
pass
@abstractmethod
def special_attack(self):
pass
def take_damage(self, damage):
self.health -= damage
if self.health < 0:
self.health = 0
def heal(self):
self.health += self.vitality
return self.health
def __str__(self):
return f"Name: {self.name}, Health: {self.health}, Attack: {self.attack}, Defense: {self.defense}"