-
Notifications
You must be signed in to change notification settings - Fork 1
/
inventory.py
64 lines (58 loc) · 2.56 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
59
60
61
62
63
from weapons import Weapons
from weapons import Sword
def inventory(equipped_weapon, gold, inventory, hero):
while True:
print('Here is your current weapon: {}'.format(equipped_weapon))
print('Here is your current gold: {}'.format(gold))
print('Here is your inventory:')
hero.print_inventory()
print('What would you like to do? (type \'exit\' to exit)')
print('1. change weapon')
print('2. drop item')
while True:
user_input = input()
if user_input == "1":
wi = list(equip_weapon(equipped_weapon, inventory))
equipped_weapon = wi[0]
inventory = wi[1]
return equipped_weapon, gold, inventory
elif user_input == "2":
wi = list(drop_item(equipped_weapon, inventory))
equipped_weapon = wi[0]
inventory = wi[1]
return equipped_weapon, gold, inventory
elif user_input == "exit":
return equipped_weapon, gold, inventory
else:
print("Invalid input {}".format(user_input))
def equip_weapon(equipped_weapon, inventory):
while True:
equip = input('which weapon would you like to equip? (type exit to cancel)')
print(equip)
if equip in inventory:
print('equipped the {}'.format(equip))
keys = list(inventory.keys())
equipped_weapon_index = keys.index(equip)
equipped_weapon = keys[equipped_weapon_index]
return equipped_weapon, inventory
elif equip.lower() == 'exit':
return equipped_weapon, inventory
else:
print('Item {} not in inventory, please try again'.format(equip))
def drop_item(equipped_weapon, inventory):
while True:
dropped_item = input('which item would you like to drop? (type exit to cancel)')
if dropped_item in inventory:
if dropped_item == equipped_weapon and len(inventory[dropped_item]) == 1:
print("Cannot drop the currently equipped weapon!")
return equipped_weapon, inventory
else:
print('dropped the {}'.format(dropped_item))
inventory[dropped_item].pop(0)
if len(inventory[dropped_item]) == 0:
del inventory[dropped_item]
return equipped_weapon, inventory
elif dropped_item.lower() == 'exit':
return equipped_weapon, inventory
else:
print('Item not in inventory, please try again')