我如何在 python 中担任游戏总监?
How do i make a game director in python?
我试图在 python 中创建一个游戏总监,但失败得很惨,因为当我尝试打开第二个程序时,它按顺序执行,所以首先是 1,然后是 2,等等这是一部分我的代码:
*import os
print('What game do you want to play?')
print('1. Hangman')
print('2. Dragon Realm')
print('3. Crafting Challenge')
gamechoice = input()
if gamechoice == '1':
print('Ok, sending you there...')
os.startfile('hangman.py')
gamechoice = input()
if gamechoice == '2':
print('Ok, sending you there...')
os.startfile('Dragon Realm.py')
gamechoice = input()
if gamechoice == '3':
print('Ok, sending you there...')
os.startfile('crafting challenge.py')*
您只需输入一次。在 if 语句中,您需要正确缩进,这样您就不会执行您不是故意的代码。
类似这样的方法可能有效:
import os
print('What game do you want to play?')
print('1. Hangman')
print('2. Dragon Realm')
print('3. Crafting Challenge')
gamechoice = input()
print('Ok, sending you there...')
if gamechoice == 1:
os.startfile('hangman.py')
elif gamechoice == 2:
os.startfile('Dragon Realm.py')
elif gamechoice == 3:
os.startfile('crafting challenge.py')
我试图在 python 中创建一个游戏总监,但失败得很惨,因为当我尝试打开第二个程序时,它按顺序执行,所以首先是 1,然后是 2,等等这是一部分我的代码:
*import os
print('What game do you want to play?')
print('1. Hangman')
print('2. Dragon Realm')
print('3. Crafting Challenge')
gamechoice = input()
if gamechoice == '1':
print('Ok, sending you there...')
os.startfile('hangman.py')
gamechoice = input()
if gamechoice == '2':
print('Ok, sending you there...')
os.startfile('Dragon Realm.py')
gamechoice = input()
if gamechoice == '3':
print('Ok, sending you there...')
os.startfile('crafting challenge.py')*
您只需输入一次。在 if 语句中,您需要正确缩进,这样您就不会执行您不是故意的代码。
类似这样的方法可能有效:
import os
print('What game do you want to play?')
print('1. Hangman')
print('2. Dragon Realm')
print('3. Crafting Challenge')
gamechoice = input()
print('Ok, sending you there...')
if gamechoice == 1:
os.startfile('hangman.py')
elif gamechoice == 2:
os.startfile('Dragon Realm.py')
elif gamechoice == 3:
os.startfile('crafting challenge.py')