feat(shop): initial shop implementation with buy functionality and item loading

This commit is contained in:
Niklas Haiden
2026-05-08 16:44:47 +02:00
parent 2adc490f3d
commit 10e094d969
+29
View File
@@ -0,0 +1,29 @@
from src.item import Item
class Shop:
def __init__(self, ects, buyable_items):
self.ects = ects # give the ects object ot the shop
self.buyable_items: list[Item] = buyable_items # give the buyable items to the shop
def buy(self, item_name):
item_to_buy = self.get_item(item_name)
if item_to_buy is None:
return False
cost = item_to_buy.get_cost()
if self.ects.is_over_balance(cost):
return False
self.ects.decrease_balance(cost)
# self.buyable_items.remove(item_to_buy)
return True
def get_item(self, item_name):
for item in self.buyable_items:
if item.item_type == item_name:
return item
return None
def get_items(self):
return self.buyable_items