This commit is contained in:
Yohann D'ANELLO
2020-11-06 15:33:26 +01:00
parent e00d98739a
commit 8ccb74ea54
8 changed files with 83 additions and 63 deletions

View File

@ -11,11 +11,12 @@ class Map:
height: int
tiles: list
def __init__(self, width: int, height: int, tiles: list, entities = []):
def __init__(self, width: int, height: int, tiles: list,
entities: list = None):
self.width = width
self.height = height
self.tiles = tiles
self.entities = entities
self.entities = entities or []
@staticmethod
def load(filename: str):
@ -40,7 +41,6 @@ class Map:
return Map(width, height, tiles, [])
def draw_string(self) -> str:
"""
Draw the current map as a string object that can be rendered
@ -72,10 +72,15 @@ class Entity:
def move(self, x: int, y: int) -> None:
self.x = x
self.y = y
def act(self, m:Map):
def act(self, m: Map) -> None:
"""
Define the action of the entity that is ran each tick.
By default, does nothing.
"""
pass
class FightingEntity(Entity):
maxhealth: int
health: int
@ -84,13 +89,13 @@ class FightingEntity(Entity):
def __init__(self):
self.health = self.maxhealth
def hit(self, opponent) -> None:
def hit(self, opponent: "FightingEntity") -> None:
opponent.take_damage(self, self.strength)
def take_damage(self, attacker, amount:int) -> None:
def take_damage(self, attacker: "Entity", amount: int) -> None:
self.health -= amount
if self.health <= 0:
self.die()
def die(self) -> None:
pass
pass