feat(shop): initial shop implementation with buy functionality and item loading
This commit is contained in:
+29
@@ -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
|
||||
Reference in New Issue
Block a user