vendredi 3 mai 2019

How can I have the randomly generated number be different each time in the whileloop?

The problem I am facing is that the randomly generated number in the value should be random when I do a usercasting. However, it is constantly the same with all the values as soon as the loop starts


hp = 1000
Fireball = random.randint(5, 10)
Iceblast = random.randint(0, 20)
Healingtouch = random.randint(5, 10)

MiniBug = 100
bspell1 = random.randint(0, 5)
bspell2 = random.randint(10, 20)
bspell3 = 15
bheal1 = 10
bossturn = random.choice([bspell3, bspell2, bspell1, bheal1])

while MiniBug >= 0:
    usercasting = input("Cast a Spell: ")
    if usercasting == "Fireball":
        print("Your spell did ", Fireball, "damage to the enemy!")
        MiniBug -= Fireball
        print("MiniBug has", MiniBug, "Hp left!")

    if usercasting == "Iceblast":
        MiniBug -= Iceblast
        print("Your spell did ", Iceblast, "damage to the enemy!")
        print("MiniBug has", MiniBug, "Hp left!")

    if usercasting == "Healingtouch":
        hp += Healingtouch
        print("You healed yourself by", Healingtouch, "!")
        print(hp)

    if MiniBug != 0:
        if bossturn == bspell1:
            hp -= bspell1
            print("The enemy attacked you for", bspell1, ",and your current hp is", hp)
        if bossturn == bspell2:
            hp -= bspell2
            print("The enemy attacked you for", bspell2, "and your current hp is", hp)
        if bossturn == bspell3:
            hp -= bspell3
            print("The enemy attacked you for", bspell3, ", and your current hp is", hp)
        if bossturn == bheal1:
            MiniBug += bheal1
            print("The enemy healed himself by", bheal1, "and his hp is", MiniBug)


The result I am looking for is to have randomly generated numbers after each "usercasting" and when it is the bossturn.




Aucun commentaire:

Enregistrer un commentaire