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

100 lines
3.5 KiB
Python

from abc import ABC, abstractmethod
from typing import override
class Unit(ABC):
def __init__(self, strength: float, dexterity: float, constitution: float, wisdom: float, intelligence: float, charisma: float):
self.strength: float = strength
self.dexterity: float = dexterity
self.constitution: float = constitution
self.wisdom: float = wisdom
self.intelligence: float = intelligence
self.charisma: float = charisma
@abstractmethod
def calculate_max_health(self) -> float:
pass
@abstractmethod
def calculate_damage(self) -> float:
pass
@abstractmethod
def calculate_defense(self) -> float:
pass
# class Spell(ABC):
# def __init__(self, name: str, damage: float, mana_cost: float):
# self.name: str = name
# self.damage: float = damage
# self.mana_cost: float = mana_cost
# @abstractmethod
# def cast(self):
# pass
class Monster(Unit):
def __init__(self, strength: float, dexterity: float, constitution: float, wisdom: float, intelligence: float, charisma: float):
super().__init__(strength, dexterity, constitution, wisdom, intelligence, charisma)
self.max_health: float = self.calculate_max_health()
self.defense: float = self.calculate_max_health()
self.damage: float = 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: float, dexterity: float, constitution: float, wisdom: float, intelligence: float, charisma: float, char_class: str):
super().__init__(strength, dexterity, constitution, wisdom, intelligence, charisma)
self.character_class: str = char_class
self.max_health: float = self.calculate_max_health()
self.defense: float = self.calculate_max_health()
self.damage: float = self.calculate_damage()
# self.max_mana: float = self.calculate_max_mana()
@override
def calculate_max_health(self):
return self.constitution * 10 + self.strength / 2
@override
def calculate_damage(self) -> float:
if self.character_class == "warrior":
return self.strength * 2.2 + self.constitution / 3
elif self.character_class == "mage":
return self.intelligence * 2.5 + self.wisdom / 2
elif self.character_class == "hunter":
return self.dexterity * 1.9 + self.strength / 3
else:
return 0
@override
def calculate_defense(self):
if self.character_class == "warrior":
return self.constitution * 1.8 + self.strength / 4
elif self.character_class == "mage":
return self.wisdom * 1.3 + self.intelligence / 6
elif self.character_class == "hunter":
return self.dexterity * 1.6 + self.constitution / 5
else:
return 0
# def calculate_max_mana(self):
# if self.character_class == "warrior":
# return self.intelligence + self.strength // 2
# elif self.character_class == "mage":
# return self.wisdom * 3 + self.intelligence
# elif self.character_class == "hunter":
# return self.dexterity * 1.5 + self.wisdom // 2
# else:
# return 0