Python Forum

Full Version: loop doesn't advance-py3 text game
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Making a simple fighting text based game where you can fight turn based and gain xp with which you can buy more hp.armour and etc.however it needs to have a menu .curently making the shop but i made the whole thing loop so the game doesn't end after you fight or buy things.but no matter what input i enter it keeps looping main menu and i dont get errors.im really new to python .please help.thanks in advance

print ("\n"*100)
name = input("whats your name?:")
maxhp = 100
armor = 0
maxdmg = 20
mindmg = 5
xp = 0
hp = maxhp
play = 1
while (play == 1):
    print ("\n" *100)
    print ("health:"+str(hp))
    print ("max health:"+str(maxhp))
    print (" 1 to fight.2 to heal or upgrade.3 to exit")
    choice=input(":")
    if (choice == 3):
        play = 0
        choice = 0
    while (choice == 2):
        print ("\n" * 100)
        print ("your XP:" + str(xp))
        print ("1 to heal to max health: 10 XP")
        print ("2 to add 1 armour:2 XP")
        print ("3 to add 3 to max and min damage")
        print ("4 to add 10 maxhp,needs hepal:20xp")
        print ("5 to go back")
        shop=input(":")
        if (shop==5):
            print ("exiting")
            choice = 0
            break
        if (shop==1):
            if (hp == maxhp):
                print ("you are already on max HP")
                choice = 0
            else:
                if (xp >= 10):
                    hp = maxhp
                    xp = xp - 10
                    choice = 0
                else:
                    print ("you don\'t have enough xp")
else:
    exit
input returns string value - convert it to integer
choice = int(choice)
Same goes for shop
(Jun-06-2017, 02:14 PM)volcano63 Wrote: [ -> ]input returns string value - convert it to integer
choice = int(choice)
Same goes for shop

I didn't know it worked that way but instead of changing the input to a integer i changed the if a=1 to a string as if a="1"