Python Forum
loop doesn't advance-py3 text game
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
loop doesn't advance-py3 text game
#1
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
Reply
#2
input returns string value - convert it to integer
choice = int(choice)
Same goes for shop
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#3
(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"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  code won't advance to next statement MCL169 2 752 Apr-11-2023, 09:44 PM
Last Post: Larz60+
  while loop not working-I am using sublime text editor mma_python 4 1,125 Feb-05-2023, 06:26 PM
Last Post: deanhystad
  While loop not ending (Best of 10 dice game) K3nidi 3 1,486 Jul-09-2022, 09:53 AM
Last Post: K3nidi
  Skipping line in text without Restarting Loop IdMineThat 4 1,477 Apr-05-2022, 04:23 AM
Last Post: deanhystad
  For Loop and Use of Brackets to Modify Dictionary in Tic-Tac-Toe Game new_coder_231013 7 2,232 Dec-28-2021, 11:32 AM
Last Post: new_coder_231013
  For Loop Works Fine But Append For Pandas Doesn't Work knight2000 2 2,008 Dec-18-2021, 02:38 AM
Last Post: knight2000
  While loop doesn't exit KenHorse 3 2,004 Jun-20-2021, 11:05 PM
Last Post: deanhystad
  loop adventure game ilikedofs 1 1,699 May-26-2021, 12:43 AM
Last Post: bowlofred
  A text-based game [SOLVED] Gameri1 6 3,902 Apr-20-2021, 02:26 PM
Last Post: buran
  how to make a hotkey for text adventure game myn2018 2 1,966 Jan-06-2021, 10:39 PM
Last Post: myn2018

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020