I'm having trouble figuring out why this code won't run... I'm having this issue:
def show_instructions(): #print a main menu and the commands
print("Murder Mystery: Knives Out")
print("Investigate the murder, collect evidence, and find the killer!")
print("Collect 6 items to narrow down who the killer is, failure to do so will allow the killer to escape.")
print("Use Move commands: go North, go South, go East, go West")
print("Collect evidence: get 'item name'")
rooms = {'Walkway' : {'South' : 'Bar', 'North' : 'Kitchen', 'East' : 'Library', 'West' : 'Bedroom' },'Bedroom' : {'item' : 'Torn Fabric', 'East' : 'Walkway'},'Library' : {'Item' : 'a clue from a guest', 'North' : 'Office', 'Item' : 'Gun', 'West' : 'Walkway'},'Bar' : {'Item' : 'Whiskey', 'East' : 'Dining Room', 'Item': 'Bloody Steak Knife'},'Kitchen' : {'Item': 'Steak Knife', 'South': 'Walkway', 'East': 'Wine Cellar',},'Wine Cellar' :{'West': 'Kitchen', 'Item' : 'Murderer'} #villain}state = 'Walkway'def get_new_state(state,direction):new_state = statefor i in rooms:if i == state:if direction in rooms[i]:new_state=rooms[i][direction]return new_state
def get_item(state):
return rooms[state]['Item']
def show_instructions():
print("Murder Mystery Game: Knives Out")
print("Investigate the murder, collect evidence, and find the killer!")
print("Collect 6 items to narrow down who the killer is, failure to do so will allow the killer to escape.")
print("Use Move commands: go North, go South, go East, go West")
print("Collect evidence: get 'item name'")
show_instructions()
Inventory=[]
Items = ['Torn Fabric', 'Whiskey', 'Bloody Steak Knife', 'Clue from Guest', 'Gun','Steak Knife']
while(1):
print('You are in ',state)
print('Inventory:',Inventory)
Item = get_item(state)
print('You see a ',Item)
print('--------------------')
if Item == 'Murderer':
print("BANG! You got shot by the murderer... GAME OVER!")
exit(0)
direction = input('Enter your move: ')
if direction == 'go East' or direction == 'go West' or direction == 'go North' or direction == 'go South':
direction=direction[3:]
new_state=get_new_state(state,direction)
if new_state == state:
print("There's a wall on that direction... enter another direction!")
else:
state=new_stateel
if direction==str('get '+Item):
if Item in Inventory:
print("There are no new items, go to a different room....")
else:
Inventory.append(Item)
else:
print("Invalid input or move or Item")
if len(Inventory)==6:
print("Congratulations! You have gathered all of the evidence and caught the Murderer!")
print("The Police arrive and have the Murderer in custody, great job!")
print("GAME OVER")
print("-----------------------------------------------------------------------------------")
exit(0)
It looks like the room 'Walkway' is missing the 'Item' key.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.