程序运行但不会调用函数

时间:2019-05-24 15:35:47

标签: python-2.7

如果运行此程序将打开菜单,但是键入1或2则仅返回菜单。不知道这意味着什么,我对python还是很陌生,所以如果它的组织性或完善性不好,我感到抱歉。我需要帮助找出原因,以便对其进行修复。

在多个不同的编译器,repl顶棚和python命令行中运行它。

end = 'false'
while end != 'true':
    import random
    monsterhp = 30
    monsterap = 10
    hp = 30
    gold = 0
    rooms = 0
    hppotions = 0
    strength = 20
    strpotion = 0
    score = gold + rooms
    def itemdrop():
        global gold
        item = random.randint(0,3)
        if item == 1:
            items = "gold pecies"
            goldrop = random.randint(0,20)
            gold += goldrop
            print('Items gathered was ',goldrop,' ',items)
        if item == 2:
            items = 'Health potions: +5 hp'
            goldrop = random.randint(0,5)
            print('Items gathered was ',goldrop,' ',items)
        if item == 3:
            items = 'Strength Potion: +5 strength'
            goldrop = random.randint(0,5)
            print('Items gathered was ',goldrop,' ',items)

    def mobattack():
        global monsterhp 
        global monsterap 
        global hp 
        global gold 
        global rooms 
        global hppotions 
        global strength 
        global strpotion 
        global score 
        print('You engage in battle with the beast.')
        while monsterhp >= 1:
            print('Current Health: ',hp)
            print('Current enemy Health',monsterhp)
            print('Attack-1')
            print('Item-2')
            choice = int(input())
            if choice == 2:
                print('You have ')
                print(hppotions,' Hp Potions Left.')
                print(strpotion,' Strength Potions Left')
                print('Options are 1 or 2')
                choice = int(input())
                if choice == 1:
                    if hppotions > 0:
                        hp += 5
                        print('HP +5')
                    else: 
                        print('No Hp Potions Left')
                if choice == 2:
                    if strpotion > 0:
                        strength += 5
                        print('Str +5')
                    else: 
                        print('No Str Potions Left')
            if choice == 1:
                hattack = random.randint(5,strength)
                print('You attack the beast for ',hattack)
                monsterhp -= hattack
            mattack = random.randint(0,monsterap)
            print('The monster attacks taking ',mattack,' Hp')
            hp -= mattack
            if hp <= 0:
                monsterhp = 0
    def cls(): #clear screen
        a = 1
        while a < 250:
            print('')
            a += 1
    def exits():
        import random
        exit = random.randint(0,3)
        if exit == 1:
                e = "to the left. "
                return e
        if exit == 2:
                e = "to the right. "
                return e
        if exit == 3:
                e = "to the left and right. "
                return e
        else:
            e = "to the left and right. "
            return e
    def endgame():
        global gold
        global rooms
        score = gold + rooms
        print("You Have Died. Your score was ",score)
        menue()
    def room():
        global rooms
        global strength
        global strpotion
        rooms += 1
        print('Room number: ',rooms)
        cort = random.randint(0,900)
        print(cort)
        if cort == range(800,900):
            e = exits()
            print('You enter a room with exit/s ',e,'With a monster in front of you.')
            mobattack()

        if cort == range(0,100):
            e = exits()
            print('You enter a room with exit/s ',e,'With a chest in front of you.')
            choice = str(input())
            if choice == "left":
                room()
            if choice == "open chest":
                gorh = 1
                if gorh == 1:
                    g = str(itemdrop())
                    print(g)
                    print('You enter a room with exit/s ',e,'With a open chest in front of you.')
                    choice = str(input())
                    if choice == "left" or "right":
                        room()
                if gorh == 2:
                    global hp 
                    hp -= random.randint(0,10)
                    if hp <0:
                        endgame()
                    else:
                        print('The chest was a trap your hp is now ',hp)

            print('You enter a room with exit/s ',e,'With a open chest in front of you.')
            choice = str(input())
            if choice == "left" or "right":
                room()
        if rooms > 100 or score >=300:
            print('You have found the exit! You win with a score of ',score,'!')
        if cort == range(101,799):
            e = exits()
            print('You enter a room with exits ',e)
            choice = str(input())
            if choice == "left" or "right":
                room()
    def menue():
        cls()
        print('Welcome to game name under construction')
        print('')
        print('')
        print('Start-1')
        print('Exit-3')
        print('Credits-2')
        mench = int(input()) #menue choice
        if mench == 1:
           room()
        if mench == 2:
            print('Everything Schaeffer')
            menue()
        if mench == 3:
            global end
            end = 'true'
    menue()

输出应该是随机生成的地牢搜寻器,但是我得到的只是菜单。

0 个答案:

没有答案