Python从脚本退出并返回主页

时间:2014-05-28 15:47:46

标签: python exit

我试图制作一个简单的基于文本的游戏来提高我的Python知识,并且我已经创建了一个位于另一个Python文件中的小型战斗系统。我调用这个系统的方法是导入文件,然后调用start函数。我遇到的问题实际上是让脚本停止并返回主脚本,以便玩家可以继续游戏。这是目前为止的相关代码:

Fight.py

def fight():
    global enemy_health
    global enemy

    if health <= 0:
        print "You have died!"
        return False
    elif enemy_health <= 0:
        print "You have killed the %s!" % enemy
        return True

    print "You have %d health." % health
    print "The enemy has %d health." % enemy_health

    while True:
        choice = raw_input("> ")
        if choice == "stab":
            pDamage = random.randrange(2, 4)
            enemy_health -= pDamage
            print "You stab the %s and deal %d damage!" % (enemy, pDamage)
            enemyTurn()
        elif choice == "slash":
            pDamage = random.randrange(1, 6)
            enemy_health -= pDamage
            print "You slash the %s and deal %d damage!" % (enemy, pDamage)
            enemyTurn()
        elif choice == "chop":
            pDamage = random.randrange(2, 7)
            enemy_health -= pDamage
            print "You chop the %s and deal %d damage!" % (enemy, pDamage)
            enemyTurn()
        else:
            print "You can slash, stab, or chop the enemy!"

Game.py

elif command == "look":
    fight.start()
    fightResults = fight.fight()
    if fightResults == True:
        print "You've won the game!"
    elif fightResults == False:
        print "You've lost the game!"
        exit(0)

所以,问题在于当玩家赢或输并且Fight.py返回一个值时,整个游戏退出。任何帮助解决这个问题将不胜感激。提前谢谢!

0 个答案:

没有答案
相关问题