Test heart healing
This commit is contained in:
parent
8db00bcaa6
commit
61714a5129
|
@ -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)
|
||||
|
||||
|
||||
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):
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue