2021-05-08 22:15:26 +02:00
|
|
|
class InventoryComponent:
|
2021-05-21 20:14:00 +02:00
|
|
|
def __init__(self, maxitems = 10):
|
2021-05-08 22:15:26 +02:00
|
|
|
self.maxitems = maxitems
|
|
|
|
self.items = {}
|
|
|
|
|
|
|
|
def addItem(self, item, count):
|
|
|
|
if item not in self.items:
|
|
|
|
self.items[item] = count
|
|
|
|
else:
|
|
|
|
self.items[item] = self.items[item] + count
|
|
|
|
if self.items[item] > self.maxitems:
|
|
|
|
self.items[item] = self.maxitems
|
|
|
|
|
|
|
|
def removeItem(self, item, count):
|
|
|
|
if self.items:
|
|
|
|
self.items[item] = self.items[item] - count
|
|
|
|
if self.items[item] < 0:
|
|
|
|
self.items[item] = 0
|
|
|
|
|
|
|
|
def hasItem(self, item):
|
|
|
|
if self.items[item] != 0:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|