module 2
This commit is contained in:
parent
aaf73e14c1
commit
82341dfa3a
1 changed files with 63 additions and 13 deletions
76
game.py
76
game.py
|
|
@ -2,28 +2,45 @@ from abc import ABC, abstractmethod
|
||||||
from typing import override
|
from typing import override
|
||||||
|
|
||||||
class Unit(ABC):
|
class Unit(ABC):
|
||||||
def __init__(self, strength, dexterity, constitution, wisdom, intelligence, charisma):
|
def __init__(self, strength: float, dexterity: float, constitution: float, wisdom: float, intelligence: float, charisma: float):
|
||||||
self.strength = strength
|
self.strength: float = strength
|
||||||
self.dexterity = dexterity
|
self.dexterity: float = dexterity
|
||||||
self.constitution = constitution
|
self.constitution: float = constitution
|
||||||
self.wisdom = wisdom
|
self.wisdom: float = wisdom
|
||||||
self.intelligence = intelligence
|
self.intelligence: float = intelligence
|
||||||
self.charisma = charisma
|
self.charisma: float = charisma
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def calculate_max_health(self):
|
def calculate_max_health(self) -> float:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def calculate_damage(self):
|
def calculate_damage(self) -> float:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def calculate_defense(self):
|
def calculate_defense(self) -> float:
|
||||||
pass
|
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):
|
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
|
@override
|
||||||
def calculate_damage(self):
|
def calculate_damage(self):
|
||||||
return self.strength * 2 + self.constitution / 5
|
return self.strength * 2 + self.constitution / 5
|
||||||
|
|
@ -36,15 +53,48 @@ class Monster(Unit):
|
||||||
def calculate_defense(self):
|
def calculate_defense(self):
|
||||||
return self.constitution * 1.2 + self.strength / 5
|
return self.constitution * 1.2 + self.strength / 5
|
||||||
|
|
||||||
|
|
||||||
class Character(Unit):
|
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
|
@override
|
||||||
def calculate_max_health(self):
|
def calculate_max_health(self):
|
||||||
return self.constitution * 10 + self.strength / 2
|
return self.constitution * 10 + self.strength / 2
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def calculate_damage(self):
|
def calculate_damage(self) -> float:
|
||||||
return self.strength * 1.5 + self.dexterity / 4
|
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
|
@override
|
||||||
def calculate_defense(self):
|
def calculate_defense(self):
|
||||||
return self.constitution * 1.5 + self.dexterity / 3
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue