Inventory
##Inventory
AtAt the moment, you are using global
variables for your inventory, which is a bad sign. The function for displaying the inventory:
Rooms
##Rooms
SecondSecond, you have the function room_sides
which gets passed lots of arguments, each corresponding to the same variables for different rooms. Compare to:
##Inventory
At the moment, you are using global
variables for your inventory, which is a bad sign. The function for displaying the inventory:
##Rooms
Second, you have the function room_sides
which gets passed lots of arguments, each corresponding to the same variables for different rooms. Compare to:
Inventory
At the moment, you are using global
variables for your inventory, which is a bad sign. The function for displaying the inventory:
Rooms
Second, you have the function room_sides
which gets passed lots of arguments, each corresponding to the same variables for different rooms. Compare to:
Checking whether the user has the item needed is now the relatively clear:
if 'hammer' in inventory:
as opposed to:
if item_use == 1:
This has also removed reliance on the order in which things are collected, so if you later decide to extend your game it will be much easier.
This has also removed reliance on the order in which things are collected, so if you later decide to extend your game it will be much easier.
Checking whether the user has the item needed is now the relatively clear:
if 'hammer' in inventory:
as opposed to:
if item_use == 1:
This has also removed reliance on the order in which things are collected, so if you later decide to extend your game it will be much easier.
def perform_action():
choices = {1: True, 2: False}
while True:
try:
choice = int(input('(1 for yes, 2 for no)\n'))
except ValueError:
print("Not valid input")
else:
if choice in choices:
return choices[choice]
print("Not valid input")
def room_sides(room, inventory):
if room['completed']:
input('\nNothing of interest here.\n')
else:
input(room['intro'])
print(room['question'])
if perform_action():
if room['item needed'] is None or room['item needed'] in inventory:
for key in ['process', 'outcome', 'item found']:
input(room[key])
inventory.append(room['item'])
room['completed'] = True
else:
print("That won't work.\n")
else:
input("\nI'll leave it alone for now.\n")
main_hub()
def perform_action():
choices = {1: True, 2: False}
while True:
try:
choice = int(input('(1 for yes, 2 for no)\n'))
except ValueError:
print("Not valid input")
else:
if choice in choices:
return choices[choice]
print("Not valid input")
def room_sides(room, inventory):
if room['completed']:
input('\nNothing of interest here.\n')
else:
input(room['intro'])
print(room['question'])
if perform_action():
if room['item needed'] is None or room['item needed'] in inventory:
for key in ['process', 'outcome', 'item found']:
input(room[key])
inventory.append(room['item'])
room['completed'] = True
else:
print("That won't work.\n")
else:
input("\nI'll leave it alone for now.\n")
main_hub()
def perform_action():
choices = {1: True, 2: False}
while True:
try:
choice = int(input('(1 for yes, 2 for no)\n'))
except ValueError:
print("Not valid input")
else:
if choice in choices:
return choices[choice]
print("Not valid input")
def room_sides(room, inventory):
if room['completed']:
input('\nNothing of interest here.\n')
else:
input(room['intro'])
print(room['question'])
if perform_action():
if room['item needed'] is None or room['item needed'] in inventory:
for key in ['process', 'outcome', 'item found']:
input(room[key])
inventory.append(room['item'])
room['completed'] = True
else:
print("That won't work.\n")
else:
input("\nI'll leave it alone for now.\n")
main_hub()