Test buying an item when we don't have enough of money

This commit is contained in:
Yohann D'ANELLO
2020-12-11 17:28:16 +01:00
parent 7179346e2b
commit 99352bc1d5
3 changed files with 17 additions and 24 deletions

View File

@ -14,11 +14,12 @@ class Item(Entity):
A class for items
"""
held: bool
held_by: Optional[Player]
held_by: Optional[InventoryHolder]
price: int
def __init__(self, held: bool = False, held_by: Optional[Player] = None,
price: int = 2, *args, **kwargs):
def __init__(self, held: bool = False,
held_by: Optional[InventoryHolder] = None,
price: int = 2, *args, **kwargs):
super().__init__(*args, **kwargs)
self.held = held
self.held_by = held_by
@ -45,7 +46,7 @@ class Item(Entity):
Indicates what should be done when the item is equipped.
"""
def hold(self, player: "Player") -> None:
def hold(self, player: InventoryHolder) -> None:
"""
The item is taken from the floor and put into the inventory
"""
@ -66,15 +67,14 @@ class Item(Entity):
def get_all_items() -> list:
return [BodySnatchPotion, Bomb, Heart, Sword]
def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder,
game: Any) -> bool:
def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool:
"""
Does all necessary actions when an object is to be sold.
Is overwritten by some classes that cannot exist in the player's
inventory
"""
if buyer.hazel >= self.price:
buyer.add_to_inventory(self)
self.hold(buyer)
seller.remove_from_inventory(self)
buyer.change_hazel_balance(-self.price)
seller.change_hazel_balance(self.price)
@ -109,22 +109,6 @@ class Heart(Item):
d["healing"] = self.healing
return d
def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder,
game: Any) -> bool:
"""
Does all necessary actions when an object is to be sold.
Is overwritten by some classes that cannot exist in the player's
inventory
"""
if buyer.hazel >= self.price:
self.hold(buyer)
seller.remove_from_inventory(self)
buyer.change_hazel_balance(-self.price)
seller.change_hazel_balance(self.price)
return True
else:
return False
class Bomb(Item):
"""