-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinventory.py
58 lines (54 loc) · 1.97 KB
/
inventory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from wallet import *
from shops import *
# Inventory
class Inventory(object):
foodInv = dict()
drinkInv = dict()
decorInv = dict()
inventory = [foodInv,drinkInv,decorInv]
def __init__(self, person):
self.person = person
def buy(self, shop, item, num):
sale = shop.sell(item, num)
if sale != False:
totalPrice = sale*num
funds = self.wallet.purchase(totalPrice)
if funds == True:
# add to food
if item.objType == 'food':
if item not in Inventory.foodInv:
Inventory.foodInv[item] = num
else:
Inventory.foodInv[item] += num
# add to drinks
if item.objType == 'drink':
if item not in Inventory.drinkInv:
Inventory.drinkInv[item] = num
else:
Inventory.drinkInv[item] += num
# add to decor
if item.objType == 'decor':
if item not in Inventory.decorInv:
Inventory.decorInv[item] = num
else:
Inventory.decorInv[item] += num
return True
return False
@staticmethod
def use(item):
if item.objType == 'food':
if item in Inventory.foodInv:
if Inventory.foodInv[item] > 0:
Inventory.foodInv[item] -= 1
return True
elif item.objType == 'drink':
if item in Inventory.drinkInv:
if Inventory.drinkInv[item] > 0:
Inventory.drinkInv[item] -= 1
return True
elif item.objType == 'decor':
if item in Inventory.decorInv:
if Inventory.decorInv[item] > 0:
Inventory.decorInv[item] -= 1
return True
return False