From 61714a51293b741f2c81ed9b34844107c257d70a Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 11 Nov 2020 17:15:28 +0100 Subject: [PATCH] Test heart healing --- dungeonbattle/entities/items.py | 9 ++------- dungeonbattle/tests/entities_test.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dungeonbattle/entities/items.py b/dungeonbattle/entities/items.py index 989b52f..e4eb74d 100644 --- a/dungeonbattle/entities/items.py +++ b/dungeonbattle/entities/items.py @@ -7,9 +7,6 @@ from ..interfaces import Entity, FightingEntity, Map class Item(Entity): held: bool held_by: Optional["Player"] - # When it is False, items disappear when they are hold. - # Action is done when the item is picked up. - can_be_in_inventory: bool = True def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -25,13 +22,11 @@ class Item(Entity): self.held = True self.held_by = player self.map.remove_entity(self) - if self.can_be_in_inventory: - player.inventory.append(self) + player.inventory.append(self) class Heart(Item): name: str = "heart" - can_be_in_inventory: bool = False healing: int = 5 def hold(self, player: "Player") -> None: @@ -39,7 +34,7 @@ class Heart(Item): When holding a heart, heal the player and don't put item in inventory. """ player.health = min(player.maxhealth, player.health + self.healing) - return super().hold(player) + self.map.remove_entity(self) class Bomb(Item): diff --git a/dungeonbattle/tests/entities_test.py b/dungeonbattle/tests/entities_test.py index 7a81d63..015d6be 100644 --- a/dungeonbattle/tests/entities_test.py +++ b/dungeonbattle/tests/entities_test.py @@ -1,6 +1,6 @@ import unittest -from dungeonbattle.entities.items import Bomb, Item +from dungeonbattle.entities.items import Bomb, Heart, Item from dungeonbattle.entities.monsters import Hedgehog from dungeonbattle.entities.player import Player from dungeonbattle.interfaces import Entity, Map @@ -93,6 +93,19 @@ class TestEntities(unittest.TestCase): item.act(self.map) self.assertTrue(hedgehog.dead) + def test_hearts(self) -> None: + """ + Test some random stuff with hearts. + """ + item = Heart() + self.map.add_entity(item) + item.move(2, 6) + self.player.health -= 2 * item.healing + self.player.move_down() + self.assertNotIn(item, self.map.entities) + self.assertEqual(self.player.health, + self.player.maxhealth - item.healing) + def test_players(self) -> None: """ Test some random stuff with players.