diff --git a/dungeonbattle/entities/__init__.py b/dungeonbattle/entities/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dungeonbattle/entities/items.py b/dungeonbattle/entities/items.py new file mode 100644 index 0000000..23a1c6e --- /dev/null +++ b/dungeonbattle/entities/items.py @@ -0,0 +1,33 @@ +from ..interfaces import Entity, FightingEntity + +class Item(Entity): + held:bool + + def __init__(self, *args, **kwargs): + super().__init__(self, *args, **kwargs) + self.held = False + + def drop(self, x:int, y:int): + self.held = False + self.move(x, y) + + def hold(self): + self.held = True + +class Bomb(Item): + damage:int = 5 + exploding:bool + + def __init__(self, *args, **kwargs): + super().__init__(self, *args, **kwargs) + self.exploding = False + + def drop(self, x:int, y:int): + super.drop(self, x, y) + self.exploding = True + + def act(self, map): + if self.exploding: + for e in map.entities: + if abs (e.x - self.x) + abs (e.y - self.y) <= 1 and isinstance(e,FightingEntity): + e.take_damage(self, self.damage) diff --git a/dungeonbattle/entities/monsters.py b/dungeonbattle/entities/monsters.py new file mode 100644 index 0000000..9aa6c06 --- /dev/null +++ b/dungeonbattle/entities/monsters.py @@ -0,0 +1,9 @@ +from ..interfaces import FightingEntity + +class Monster(FightingEntity): + def act(self, map): + pass + +class Squirrel(Monster): + maxhealth = 10 + strength = 3 diff --git a/dungeonbattle/entities/player.py b/dungeonbattle/entities/player.py new file mode 100644 index 0000000..b687366 --- /dev/null +++ b/dungeonbattle/entities/player.py @@ -0,0 +1,5 @@ +from ..interfaces import FightingEntity + +class Player(FightingEntity): + maxhealth = 20 + strength = 5 diff --git a/dungeonbattle/interfaces.py b/dungeonbattle/interfaces.py index 5823352..f1474e0 100644 --- a/dungeonbattle/interfaces.py +++ b/dungeonbattle/interfaces.py @@ -11,7 +11,7 @@ class Map: height: int tiles: list - def __init__(self, width: int, height: int, tiles: list, entities: list): + def __init__(self, width: int, height: int, tiles: list, entities = []): self.width = width self.height = height self.tiles = tiles @@ -37,8 +37,10 @@ class Map: width = len(lines[0]) tiles = [[Tile(c) for x, c in enumerate(line)] for y, line in enumerate(lines)] + return Map(width, height, tiles, []) + def draw_string(self) -> str: """ Draw the current map as a string object that can be rendered @@ -64,15 +66,31 @@ class Tile(Enum): class Entity: - y: int x: int - img: str - - def __init__(self, y: int, x: int, img: str): - self.y = y - self.x = x - self.img = img + y: int def move(self, x: int, y: int) -> None: self.x = x self.y = y + + def act(self, m:Map): + pass + +class FightingEntity(Entity): + maxhealth: int + health: int + strength: int + + def __init__(self): + self.health = self.maxhealth + + def hit(self, opponent) -> None: + opponent.take_damage(self, self.strength) + + def take_damage(self, attacker, amount:int) -> None: + self.health -= amount + if self.health <= 0: + self.die() + + def die(self) -> None: + pass