I am new to Python and am trying to build a battle simulation program. I am stuck with having my random generated numbers re-generate while in the while loop. The program will generate a random number once and use that number through the program for each loop until the program ends. Here are the parts in the program where is will do this:
orc_atk = random.randint(1, 2)
if orc_atk == 1:
print("You get hit and take " + str(Orc.damage - Warrior.armor) + " damage.\nYou have " + str(Warrior.player_hp - (Orc.damage - Warrior.armor)) + "HP left!")
Warrior.player_hp -= (Orc.damage - Warrior.armor)
if orc_atk == 2:
print("You dodge the Orc attack!")
both of these programs work but they keep the random number generated and won't re-generate for each loop.
Aucun commentaire:
Enregistrer un commentaire