Я новичок в Python и пытаюсь создать программу симуляции битвы.Я застрял с повторной генерацией случайных чисел во время цикла while.Программа будет генерировать случайное число один раз и использовать его через программу для каждого цикла, пока программа не завершится.Вот программа:
import time
from Weapon import wepn
from Axe import Axe
from Player import Player
from Enemy import Enmy
import random
big_axe = Axe(random.randint(12, 40))
Excalibur = wepn(random.randint(10, 35))
Orc = Enmy(100, random.randint(20, 40))
Warrior = Player(100, random.randint(10, 25), 15)
potion = 25
potion_num = 4
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!")
while Orc.enemy_hp > 0 and Warrior.player_hp > 0:
time.sleep(1.5)
choice = input("\nThe Orc charges at you, what do you do?\nA) Use Sword\nB) Use Axe \nC) Use Potion\n")
if choice == "a":
time.sleep(1)
print("\nYou attack the orc with your swift sword")
print("The Orc is hit, it has " + str(Orc.enemy_hp - Excalibur.damage) + "HP left!")
Orc.enemy_hp -= Excalibur.damage
print("The orc attacks you")
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!")
if choice == "b":
time.sleep(1)
print("\nYou swing your mighty axe and hit the Orc!")
print("The Orc takes " + str(big_axe.damage) + " damage, the Orc has " + str(Orc.enemy_hp - big_axe.damage) + " HP left!")
Orc.enemy_hp -= big_axe.damage
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!")
if choice == "c":
if potion_num > 0:
time.sleep(1)
print("You use a potion.\nYour HP is now " + str(Warrior.player_hp + potion))
potion_num -= 1
print("You have " + str(potion_num) + " potion(s) left.")
Warrior.player_hp += potion
if potion_num == 0:
print("You are out of potions.")
if Enmy.is_alive(Orc):
print("The Orc still lives")
if not Player.still_fighting(Warrior):
print("You were defeated!")
if not Enmy.is_alive(Orc):
print("You defeated the Orc!")