fix: fix buying logic for shop
This commit is contained in:
+5
-4
@@ -3,8 +3,8 @@ from src.item import Item
|
|||||||
|
|
||||||
class Shop:
|
class Shop:
|
||||||
def __init__(self, ects, buyable_items):
|
def __init__(self, ects, buyable_items):
|
||||||
self.ects = ects # give the ects object ot the shop
|
self.ects = ects # give the ects object to the shop
|
||||||
self.buyable_items: list[Item] = buyable_items # give the buyable items to the shop
|
self.buyable_items: list[Item] = buyable_items
|
||||||
|
|
||||||
def buy(self, item_name):
|
def buy(self, item_name):
|
||||||
item_to_buy = self.get_item(item_name)
|
item_to_buy = self.get_item(item_name)
|
||||||
@@ -12,11 +12,12 @@ class Shop:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
cost = item_to_buy.get_cost()
|
cost = item_to_buy.get_cost()
|
||||||
if self.ects.is_over_balance(cost):
|
|
||||||
|
# is_over_balance() means "has enough balance"
|
||||||
|
if not self.ects.is_over_balance(cost):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.ects.decrease_balance(cost)
|
self.ects.decrease_balance(cost)
|
||||||
# self.buyable_items.remove(item_to_buy)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_item(self, item_name):
|
def get_item(self, item_name):
|
||||||
|
|||||||
Reference in New Issue
Block a user