Python 文本RPG赢得';不要从一个def转到另一个def。。。以某种方式
因此,当我在关注我自己的蜂蜡,并在网上学习如何创建文本RPG时,我遇到了一个障碍,我似乎无法找出它在代码中的位置 基本上,我试着从“让我们现在开始!”在def设置_游戏中显示def提示符,但我似乎不知道如何达到这一点 代码如下:Python 文本RPG赢得';不要从一个def转到另一个def。。。以某种方式,python,Python,因此,当我在关注我自己的蜂蜡,并在网上学习如何创建文本RPG时,我遇到了一个障碍,我似乎无法找出它在代码中的位置 基本上,我试着从“让我们现在开始!”在def设置_游戏中显示def提示符,但我似乎不知道如何达到这一点 代码如下: #Python Text RPG :D import cmd import textwrap import sys import os import time #Za Warudo import random screen_width = 100 #Player
#Python Text RPG :D
import cmd
import textwrap
import sys
import os
import time #Za Warudo
import random
screen_width = 100
#Player Setup
class player:
def __init__(self):
self.name = ''
self.job = ''
self.hp = 0
self.mp = 0
self.status_effects = []
self.location = '1'
self.game_over = False
myPlayer = player()
#Title Screen
def title_screen_selections():
option = input("> ")
if option.lower() == ("play"):
setup_game() #PLACEHOLDER
elif option.lower() == ("help"):
help_menu()
elif option.lower() == ("quit"):
sys.exit()
while option.lower() not in ['play', 'help', 'quit']:
print("Please enter a valid command.")
option = input("> ")
if option.lower() == ("play"):
setup_game() #PLACEHOLDER
elif option.lower() == ("help"):
help_menu()
elif option.lower() == ("quit"):
sys.exit()
def title_screen():
os.system('clear')
print('################')
print("# Welcome to the Text RPG! #")
print('################')
print(' - Play - ')
print(' - Help - ')
print(' - Quit - ')
print('Copyright 2021 moi')
title_screen_selections()
def help_menu():
print('################')
print("# Welcome to the Text RPG! #")
print('################')
print('- Use the numbers to choose an option (1,2,3,4) -')
print(' - Type your commands to do them - ')
print(' - Use "look" to inspect something - ')
print(' - Do not trust Simulation - ')
title_screen_selections()
#Map
ZONENAME = ''
DESCRIPTION = 'description'
EXAMINATION = 'examine'
SOLVED = False
UP = 'up', 'north'
DOWN = 'down', 'south'
LEFT = 'left', 'west'
RIGHT = 'right', 'east'
solved_places = {
'1': False, '2': False,
'3': False, '4': False,
'5': False, '6': False,
'7': False, '8': False,
'9': False, '10': False}
zonemap = {
'1': {
ZONENAME: "Level 1",
DESCRIPTION: 'The Backrooms',
EXAMINATION: 'examine',
SOLVED: False,
UP: 0,
DOWN: 2,
},
'2': {
ZONENAME: "",
DESCRIPTION: 'description',
EXAMINATION: 'examine',
SOLVED: False,
UP: 1,
DOWN: 3,
},
'3': {
ZONENAME: "",
DESCRIPTION: 'description',
EXAMINATION: 'examine',
SOLVED: False,
UP: 2,
DOWN: 4,
},
'4': {
ZONENAME: "",
DESCRIPTION: 'description',
EXAMINATION: 'examine',
SOLVED: False,
UP: 3,
DOWN: 5,
},
'5': {
ZONENAME: "",
DESCRIPTION: 'description',
EXAMINATION: 'examine',
SOLVED: False,
UP: 4,
DOWN: 6,
},
'6': {
ZONENAME: "",
DESCRIPTION: 'description',
EXAMINATION: 'examine',
SOLVED: False,
UP: 5,
DOWN: 7,
},
'7': {
ZONENAME: "",
DESCRIPTION: 'description',
EXAMINATION: 'examine',
SOLVED: False,
UP: 6,
DOWN: 8,
},
'8': {
ZONENAME: "",
DESCRIPTION: 'description',
EXAMINATION: 'examine',
SOLVED: False,
UP: 7,
DOWN: 9,
},
'9': {
ZONENAME: "",
DESCRIPTION: 'description',
EXAMINATION: 'examine',
SOLVED: False,
UP: 8,
DOWN: 10,
},
'10': {
ZONENAME: "",
DESCRIPTION: 'description',
EXAMINATION: 'examine',
SOLVED: False,
UP: 1,
},
}
#Game Interactivity
def print_location():
print('\n' + ('#' * (4 + len(myPlayer.location))))
print('# ' + myPlayer.location.upper() + ' #')
print('# ' + zonemap[myPlayer.location] [DESCRIPTION] + ' #')
print('\n' + ('#' * (4 + len(myPlayer.location))))
def prompt():
print("\n" + "===============")
print("What would you like to do?")
action = input("> ")
acceptable_actions = ['move', 'go', 'travel', 'walk', 'quit', 'examine', 'inspect', 'interact', 'look']
while action.lower() not in acceptable_actions:
print("Unknown action, try again.\n")
action = input("> ")
if action.lower() == 'quit':
sys.exit()
elif action.lower() in ['move', 'go', 'travel', 'walk']:
player_move(action.lower())
elif action.lower() in ['examine', 'inspect', 'interact', 'look']:
player_examine(action.lower())
def player_move(myAction):
ask = "Where would you like to move to?\n"
dest = input(ask)
if dest in ['up']:
destination = zonemap[myPlayer.location] [UP]
movement_handler(destination)
elif dest in ['left', 'west']:
destination = zonemap[myPlayer.location] [LEFT]
movement_handler(destination)
elif dest in ['east', 'right']:
destination = zonemap[myPlayer.location] [RIGHT]
movement_handler(destination)
elif dest in ['south', 'down']:
destination = zonemap[myPlayer.location] [DOWN]
movement_handler(destination)
def movement_handler(destination):
print("\n" + "You have moved to the " + destination + ".")
myPlayer.location = destination
print_location()
def player_examine(action):
if zonemap[myPlayer.location] [SOLVED]:
print("You have already exhausted this zone!")
else:
print("You can trigger a puzzle here.")
#Game Functionality
def main_game_loop():
# here handle if puzzles have been solved, boss defeated, explored everything, etc.
while myPlayer.game_over is False:
prompt()
#Name collecting
def setup_game():
os.system('clear')
question1 = "Hello, what's your name?\n"
for character in question1:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.05)
player_name = input("> ")
myPlayer.name = player_name
question2 = "What role do you want to play?\n"
question2added = "(You can play as a warrior, priest, or mage)\n"
for character in question2:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.05)
for character in question2added:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.05)
player_job = input("> ")
valid_jobs = ['warrior', 'mage', 'priest']
if player_job.lower() in valid_jobs:
myPlayer.job = player_job
print("You are now a " + player_job + "!")
while player_job.lower() not in valid_jobs:
print("That's not a valid job, sorry...")
player_job = input("> ")
if player_job.lower() in valid_jobs:
myPlayer.job = player_job
print("You are now a " + player_job + "!")
#PLAYER STATS
if myPlayer.job is 'warrior':
self.hp = 120
self.mp = 20
elif myPlayer.job is 'mage':
self.hp = 40
self.mp = 120
elif myPlayer.job is 'priest':
self.hp = 60
self.mp = 60
question3 = "Welcome, " + player_name + " the " + player_job + ".\n"
for character in question3:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.05)
speech1 = "Welcome to this Labyrinth!\n"
speech2 = "I hope it greets you well!\n"
speech3 = "Just make sure you don't get too lost...\n"
speech4 = "And don't trust Simulation.\n"
for character in speech1:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.03)
for character in speech2:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.03)
for character in speech3:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.1)
for character in speech4:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.2)
os.system('clear')
print("Let's start now!")
title_screen()
小提示:当它说“按1、2、3或4”时,我实际上还没有在中实现它们,所以我认为这不是问题所在
TL;博士:我正试图让代码从“让我们现在开始!”“你想做什么?”
祝您度过愉快的一天您永远不会在任何地方调用
main\u game\u loop
函数。