Add an Item subclass of Entity for instances of items on the map
This commit is contained in:
parent
e8b2729353
commit
1f750a0c7c
1 changed files with 19 additions and 0 deletions
|
@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional, Tuple, Type
|
|||
|
||||
import tcod
|
||||
|
||||
from . import items
|
||||
from .components import Fighter
|
||||
from .geometry import Point
|
||||
from .monsters import Species
|
||||
|
@ -138,3 +139,21 @@ class Monster(Actor):
|
|||
def __str__(self) -> str:
|
||||
return f'{self.name} with {self.fighter.hit_points}/{self.fighter.maximum_hit_points} hp at {self.position}'
|
||||
|
||||
class Item(Entity):
|
||||
'''An instance of an Item'''
|
||||
|
||||
def __init__(self, kind: items.Item, position: Point = None, name: str = None):
|
||||
super().__init__(kind.symbol,
|
||||
position=position,
|
||||
blocks_movement=False,
|
||||
fg=kind.foreground_color,
|
||||
bg=kind.background_color)
|
||||
self.kind = kind
|
||||
self._name = name
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
'''The name of the item'''
|
||||
if self._name:
|
||||
return self._name
|
||||
return self.kind.name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue