Textbasiertes Spiel: Item erhalten [geschlossen]Python

Python-Programme
Anonymous
 Textbasiertes Spiel: Item erhalten [geschlossen]

Post by Anonymous »

Ich erstelle ein textbasiertes Spiel für meine Python 140 -Klasse. Einer der Anforderungen ist, dass der Benutzer einen Artikel aus jedem Raum "holen" und seinem Inventar hinzufügen kann. Wenn ich den Code ausführe und versuche, den Artikel aus diesem Raum zu "abrufen", fehlerhaft mit einem Traceback für Zeile 56 "Name 'Lower' ist nicht definiert". Was mache ich falsch, damit das Spiel den Artikel nicht zum Inventar hinzufügt? < /P>

Code: Select all

print("Welcome! To defeat HUNGER, you must collect all 6 SATIATING FOODS.")

name = input("What is your name? ")

rooms = {
'FOREST': {'North': 'PUB', 'East': 'FARM', 'West': 'FIELD'},
'PUB': {'North': 'HOUSE', 'East': 'CELLAR', 'South': 'FOREST', 'West': 'RESTAURANT', 'item': 'FISH AND CHIPS'
},
'FARM': {'North': 'FARMHOUSE', 'West': 'FIELD',
'item': 'POTATOES'
},
'FIELD': {'North': 'RESTAURANT', 'East': 'FOREST',
'item': 'BERRY MEDLEY'
},
'RESTAURANT': {'East': 'PUB', 'South': 'FIELD',
'item': 'STIR FRY'
},
'FARMHOUSE': {'North': 'CELLAR', 'South': 'FARM',
'item': 'HEARTY STEW'
},
'CELLAR': {'South': 'FARMHOUSE', 'West': "PUB",
'item': 'CANNED SOUP'
},
'HOUSE': {'South': "PUB",
'item': 'HUNGER'
},

}

directions = ['North', 'South', 'East', 'West']
location = 'FOREST'
item = ['POTATOES', 'BERRY MEDLEY', 'STIR FRY', 'FISH AND CHIPS', 'HEARTY STEW', 'CANNED SOUP']
inventory = []

print("Welcome to Trials of Harvest."
"You can go North, East, South, or West. Type 'Exit' to leave the game.")

while True:  # Gameplay loop
print(f'You are in the {location}, {name}.')
print("Inventory:", inventory)
if rooms['item']:
print('Item in room: {}'.format(''.join(rooms['item'])))
print('------------------------------')

direction = input("Type North, East, South, West, or Exit: ").capitalize()

if direction in rooms[location]:  # Check if the direction exists in the current room
location = rooms[location][direction]  # Move to the new room
elif direction == "Exit":
print(f'Thanks for playing, {name}!')
break
elif lower().split()[0] == 'get':
item = " ".join(command.lower().split()[1:])
if item in rooms['item']:
Inventory.append(item)
print('You grabbed {}.'.format(rooms['item']))
else:
print("I don't see that here.")
else:
print('You cannot go that way!')

while currentRoom in ['HUNGER']:
if len(Inventory) == 6:
print('You collected all of the items, and defeated HUNGER!')
else:
print('It looks like you have not found everything, you lose!')
break

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post