From 1f750a0c7cb34338250e0e4236739e2000ac07f1 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 8 May 2022 23:37:31 -0700 Subject: [PATCH] Add an Item subclass of Entity for instances of items on the map --- roguebasin/object.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/roguebasin/object.py b/roguebasin/object.py index 25fa784..89c4bf0 100644 --- a/roguebasin/object.py +++ b/roguebasin/object.py @@ -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