我如何在python中制作游戏导演?

时间:2015-01-31 09:04:11

标签: python pygame

我试图在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')*

1 个答案:

答案 0 :(得分:1)

您只需要输入一次。在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')