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>
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
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]print("Welcome! To defeat HUNGER, you must collect all 6 SATIATING FOODS.")
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 [/code]
Ich bin neu im Programmieren. Ich möchte ein Spiel machen, bei dem der Benutzer auf ein Problem stößt und dann eine von 2-3 Optionen auswählt. Derzeit habe ich die Story/den Inhalt in HTML und...
Ich bin neu im Programmieren. Ich möchte ein Spiel machen, bei dem der Benutzer auf ein Problem stößt und dann eine von 2-3 Optionen auswählt. Derzeit habe ich die Story/den Inhalt in HTML und...
Ich bin sehr verblüfft und ist ein wenig besorgt, um das folgende Verhalten zu entdecken, bei dem ich zwei Tests und zwei Vorrichtungen habe. import pytest
Ich versuche, ein Pong-Spiel für zwei Personen zu erstellen, das von zwei verschiedenen Clients (möglicherweise auf zwei verschiedenen Computern) über eine TCP-Verbindung (Sockets) gespielt werden...
Ich habe gerade ein Upgrade auf Vuetify 3.x durchgeführt und festgestellt, dass v-list-item-action-text entfernt wurde, ohne dass dies in der Dokumentation erwähnt wurde. Hat jemand einen...