From 2ba7330ff5a91bdf96d58dc1328002418b94a4c9 Mon Sep 17 00:00:00 2001 From: Nicolas Margulies Date: Fri, 23 Oct 2020 18:02:57 +0200 Subject: [PATCH] An example of item --- dungeonbattle/entities/items.py | 20 +++++++++++++++++++- dungeonbattle/entities/monsters.py | 2 +- dungeonbattle/interfaces.py | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/dungeonbattle/entities/items.py b/dungeonbattle/entities/items.py index e88a36e..23a1c6e 100644 --- a/dungeonbattle/entities/items.py +++ b/dungeonbattle/entities/items.py @@ -1,4 +1,4 @@ -from ..interfaces import Entity +from ..interfaces import Entity, FightingEntity class Item(Entity): held:bool @@ -13,3 +13,21 @@ class Item(Entity): 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 index 6f855af..9aa6c06 100644 --- a/dungeonbattle/entities/monsters.py +++ b/dungeonbattle/entities/monsters.py @@ -1,7 +1,7 @@ from ..interfaces import FightingEntity class Monster(FightingEntity): - def behaviour(self, map): + def act(self, map): pass class Squirrel(Monster): diff --git a/dungeonbattle/interfaces.py b/dungeonbattle/interfaces.py index e2be5df..f1474e0 100644 --- a/dungeonbattle/interfaces.py +++ b/dungeonbattle/interfaces.py @@ -72,6 +72,9 @@ class Entity: 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