В настоящее время я записываюсь на вводный курс по написанию сценариев, где моим последним проектом является создание текстовой приключенческой игры. По сути, идея состоит в том, чтобы игрок перемещался по комнатам и собирал предметы, не сталкиваясь со злодеем.
Проблема, с которой я столкнулся, заключается в том, чтобы получить доступ к элементам из словаря моих комнат и затем добавить их в словарь моих комнат. список инвентаря, который я создал для игрока. Я рассмотрел несколько других примеров, но не нашел ни одного, который бы подходил для моей игры. Я не знаю, лучше ли создать совершенно новую функцию для сбора элементов, а затем попытаться включить ветвление решений, вызывающее эту функцию, или есть что-то проще.
Я прикрепил свой код ниже и хотел бы знать, с чего начать. Также, если кто-то увидит что-то еще, что можно изменить, пожалуйста, дайте мне знать. Любая помощь приветствуется.
def main_menu():
# Print the introduction and available player commands
print("Oh joy...another mortal. Well, mortal, if you would like to return to your own world feel free to "
"wander the Master's garden in search of an exit.")
print("There are six unique items you will need to collect in order to return home. Oh! And mind the Mind Flayers.")
print("They will take your sanity as surely as staying in this garden would. Good luck...")
print()
print("Move Commands: North, South, West, East")
print("Add to Inventory: get 'Item'")
print("-----------------------------------------------------------------------------------------------------")
def you_died():
print('You reach the peaceful shores of the drowned lake and suddenly you'
'feel an alien presence in your mind... It is too late to run, you are dead.')
def main():
main_menu()
# Create a dictionary to house the rooms and items
rooms = {
'Garden of Madness': {'name': 'Garden of Madness', 'South': 'Screaming Tombs', 'North': 'Bone Orchard',
'East': 'Dream Cells', 'West': 'Wraith Point', 'item': 'nothing'},
'Screaming Tombs': {'name': 'Screaming Tombs', 'North': 'Garden of Madness', 'East': 'Ghost Raven Grotto',
'item': 'a Wooden Spoon'},
'Ghost Raven Grotto': {'name': 'Ghost Raven Grotto', 'West': 'Screaming Tombs', 'item': 'Moldy Cheese'},
'Bone Orchard': {'name': 'Bone Orchard', 'South': 'Garden of Madness', 'East': 'Cheerful Mausoleum', 'item':
'a Hand'},
'Cheerful Mausoleum': {'name': 'Cheerful Mausoleum', 'West': 'Bone Orchard', 'item': 'a Book of Jokes'},
'Dream Cells': {'name': 'Dream Cells', 'West': 'Garden of Madness', 'North': 'Soul Vineyard', 'item':
'a Pretty Crystal'},
'Soul Vineyard': {'name': 'Soul Vineyard', 'South': 'Dream Cells', 'item': 'a Squirrel'},
'Wraith Point': {'name': 'Wraith Point', 'East': 'Garden of Madness', 'North': 'Drowned Lake',
'item': 'nothing'},
'Drowned Lake': {'name': 'Drowned Lake', 'item': 'the Mind Flayer!!'} # Villain!!
}
# Establish how players current location will be called
current_loc = rooms['Garden of Madness']
# Establish the current commands available to the player
commands = ['North', 'South', 'West', 'East', 'Item']
# Create a blank list for the inventory
inventory = []
# Begin the game
while True:
print('You are in the {}.'.format(current_loc['name'], )) # Print the player's current location
print('This room contains {}.'.format(current_loc['item'], )) # Print the item in the locations
print('Your Inventory: {}'.format(inventory, )) # Print the player's inventory
command = input('\nWhat would you like to do?').strip() # Get player command input
if command in commands:
if command in current_loc:
current_loc = rooms[current_loc[command]]
# FIXME game needs to call the you_died function and end the game in 'Drowned Lake'
else:
# Prompt user to choose a valid direction
print('You run headlong into a wall and take a nasty bump on your head.'
'Please try a different direction.')
elif command.lower() in 'quit': # quit command valid for testing only
print('You embrace the insanity within and skip gleefully into madness.')
break
else:
# Print statement when invalid command is given
print('The madness of this place must be getting to you. Please give a valid command.')
print()
main()
Подробнее здесь: https://stackoverflow.com/questions/680 ... -adventure
Введение в Python: текстовое приключение [закрыто] ⇐ Python
Программы на Python
-
Anonymous
1732269620
Anonymous
В настоящее время я записываюсь на вводный курс по написанию сценариев, где моим последним проектом является создание текстовой приключенческой игры. По сути, идея состоит в том, чтобы игрок перемещался по комнатам и собирал предметы, не сталкиваясь со злодеем.
Проблема, с которой я столкнулся, заключается в том, чтобы получить доступ к элементам из словаря моих комнат и затем добавить их в словарь моих комнат. список инвентаря, который я создал для игрока. Я рассмотрел несколько других примеров, но не нашел ни одного, который бы подходил для моей игры. Я не знаю, лучше ли создать совершенно новую функцию для сбора элементов, а затем попытаться включить ветвление решений, вызывающее эту функцию, или есть что-то проще.
Я прикрепил свой код ниже и хотел бы знать, с чего начать. Также, если кто-то увидит что-то еще, что можно изменить, пожалуйста, дайте мне знать. Любая помощь приветствуется.
def main_menu():
# Print the introduction and available player commands
print("Oh joy...another mortal. Well, mortal, if you would like to return to your own world feel free to "
"wander the Master's garden in search of an exit.")
print("There are six unique items you will need to collect in order to return home. Oh! And mind the Mind Flayers.")
print("They will take your sanity as surely as staying in this garden would. Good luck...")
print()
print("Move Commands: North, South, West, East")
print("Add to Inventory: get 'Item'")
print("-----------------------------------------------------------------------------------------------------")
def you_died():
print('You reach the peaceful shores of the drowned lake and suddenly you'
'feel an alien presence in your mind... It is too late to run, you are dead.')
def main():
main_menu()
# Create a dictionary to house the rooms and items
rooms = {
'Garden of Madness': {'name': 'Garden of Madness', 'South': 'Screaming Tombs', 'North': 'Bone Orchard',
'East': 'Dream Cells', 'West': 'Wraith Point', 'item': 'nothing'},
'Screaming Tombs': {'name': 'Screaming Tombs', 'North': 'Garden of Madness', 'East': 'Ghost Raven Grotto',
'item': 'a Wooden Spoon'},
'Ghost Raven Grotto': {'name': 'Ghost Raven Grotto', 'West': 'Screaming Tombs', 'item': 'Moldy Cheese'},
'Bone Orchard': {'name': 'Bone Orchard', 'South': 'Garden of Madness', 'East': 'Cheerful Mausoleum', 'item':
'a Hand'},
'Cheerful Mausoleum': {'name': 'Cheerful Mausoleum', 'West': 'Bone Orchard', 'item': 'a Book of Jokes'},
'Dream Cells': {'name': 'Dream Cells', 'West': 'Garden of Madness', 'North': 'Soul Vineyard', 'item':
'a Pretty Crystal'},
'Soul Vineyard': {'name': 'Soul Vineyard', 'South': 'Dream Cells', 'item': 'a Squirrel'},
'Wraith Point': {'name': 'Wraith Point', 'East': 'Garden of Madness', 'North': 'Drowned Lake',
'item': 'nothing'},
'Drowned Lake': {'name': 'Drowned Lake', 'item': 'the Mind Flayer!!'} # Villain!!
}
# Establish how players current location will be called
current_loc = rooms['Garden of Madness']
# Establish the current commands available to the player
commands = ['North', 'South', 'West', 'East', 'Item']
# Create a blank list for the inventory
inventory = []
# Begin the game
while True:
print('You are in the {}.'.format(current_loc['name'], )) # Print the player's current location
print('This room contains {}.'.format(current_loc['item'], )) # Print the item in the locations
print('Your Inventory: {}'.format(inventory, )) # Print the player's inventory
command = input('\nWhat would you like to do?').strip() # Get player command input
if command in commands:
if command in current_loc:
current_loc = rooms[current_loc[command]]
# FIXME game needs to call the you_died function and end the game in 'Drowned Lake'
else:
# Prompt user to choose a valid direction
print('You run headlong into a wall and take a nasty bump on your head.'
'Please try a different direction.')
elif command.lower() in 'quit': # quit command valid for testing only
print('You embrace the insanity within and skip gleefully into madness.')
break
else:
# Print statement when invalid command is given
print('The madness of this place must be getting to you. Please give a valid command.')
print()
main()
Подробнее здесь: [url]https://stackoverflow.com/questions/68012126/intro-to-python-text-based-adventure[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия