Instantiate entity attributes in __init__ rather than in the class definition
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
from enum import Enum, auto
|
||||
from math import sqrt
|
||||
from random import choice, randint
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
from dungeonbattle.display.texturepack import TexturePack
|
||||
|
||||
@ -141,7 +141,7 @@ class Map:
|
||||
"""
|
||||
self.width = d["width"]
|
||||
self.height = d["height"]
|
||||
self.start_y = d["start_y"]
|
||||
self.start_y = d["start_y"]
|
||||
self.start_x = d["start_x"]
|
||||
self.currentx = d["currentx"]
|
||||
self.currenty = d["currenty"]
|
||||
@ -192,11 +192,15 @@ class Entity:
|
||||
y: int
|
||||
x: int
|
||||
name: str
|
||||
map: Map
|
||||
map: Map
|
||||
|
||||
def __init__(self):
|
||||
self.y = 0
|
||||
self.x = 0
|
||||
# noinspection PyShadowingBuiltins
|
||||
def __init__(self, y: int = 0, x: int = 0, name: Optional[str] = None,
|
||||
map: Optional[Map] = None):
|
||||
self.y = y
|
||||
self.x = x
|
||||
self.name = name
|
||||
self.map = map
|
||||
|
||||
def check_move(self, y: int, x: int, move_if_possible: bool = False)\
|
||||
-> bool:
|
||||
@ -318,16 +322,19 @@ class FightingEntity(Entity):
|
||||
constitution: int
|
||||
level: int
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.health = self.maxhealth
|
||||
self.health = 0
|
||||
self.strength = 0
|
||||
self.intelligence = 0
|
||||
self.charisma = 0
|
||||
self.dexterity = 0
|
||||
self.constitution = 0
|
||||
self.level = 1
|
||||
def __init__(self, maxhealth: int = 0, health: Optional[int] = None,
|
||||
strength: int = 0, intelligence: int = 0, charisma: int = 0,
|
||||
dexterity: int = 0, constitution: int = 0, level: int = 0,
|
||||
*args, **kwargs) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
self.maxhealth = maxhealth
|
||||
self.health = maxhealth if health is None else health
|
||||
self.strength = strength
|
||||
self.intelligence = intelligence
|
||||
self.charisma = charisma
|
||||
self.dexterity = dexterity
|
||||
self.constitution = constitution
|
||||
self.level = level
|
||||
|
||||
@property
|
||||
def dead(self) -> bool:
|
||||
|
Reference in New Issue
Block a user