college-game/game.py
2026-09-07 02:03:48 +03:00

64 lines
1.9 KiB
Python

from abc import ABC, abstractmethod
from typing import override
class Unit(ABC):
def __init__(self, strength, dexterity, constitution, wisdom, intelligence, charisma):
self.strength = strength
self.dexterity = dexterity
self.constitution = constitution
self.wisdom = wisdom
self.intelligence = intelligence
self.charisma = charisma
@abstractmethod
def calculate_max_health(self):
pass
@abstractmethod
def calculate_damage(self):
pass
@abstractmethod
def calculate_defense(self):
pass
class Monster(Unit):
def __init__(self, strength, dexterity, constitution, wisdom, intelligence, charisma):
super().__init__(strength, dexterity, constitution, wisdom, intelligence, charisma)
self.max_health = self.calculate_max_health()
self.defense = self.calculate_max_health()
self.damage = self.calculate_damage()
@override
def calculate_damage(self):
return self.strength * 2 + self.constitution / 5
@override
def calculate_max_health(self):
return self.constitution * 8 + self.strength / 3
@override
def calculate_defense(self):
return self.constitution * 1.2 + self.strength / 5
class Character(Unit):
def __init__(self, strength, dexterity, constitution, wisdom, intelligence, charisma):
super().__init__(strength, dexterity, constitution, wisdom, intelligence, charisma)
# self.character_class = char_class
self.max_health = self.calculate_max_health()
self.defense = self.calculate_max_health()
self.damage = self.calculate_damage()
@override
def calculate_max_health(self):
return self.constitution * 10 + self.strength / 2
@override
def calculate_damage(self):
return self.strength * 1.5 + self.dexterity / 4
@override
def calculate_defense(self):
return self.constitution * 1.5 + self.dexterity / 3