I have a function and want to use time.sleep(2) everytime an attack happens, but what ends up happening is the time.sleep(2) will work for the first player and enemy attack, then the program will print the rest of the attacks instantly. Does anyone know what I'm doing wrong?
def attack(player, enemy):
firstAtt = random.randint(1, 2)#Player = 1, Enemy = 2. Checks to see who goes first.
print("BATTLE!")
print()
print("You have {0}HP, while the {1} has {2}HP.".format(player["hp"], enemy["name"], enemy["hp"]))
if firstAtt == 1:
time.sleep(2)
while player["hp"] > 0 and enemy["hp"] > 0:
dmg = player["att"]()
enemydmg = enemy["att"]()
enemy["hp"] = enemy["hp"] - dmg
print("You have dealt {0} damage to the {1}!".format(dmg, enemy["name"]))
if enemy["hp"] <= 0:
print()
print("You have killed the {0}".format(enemy["name"]))
print("You have {0}HP left.".format(player["hp"]))
break
player["hp"] = player["hp"] - enemydmg
print("The {0} has dealt {1} damage to you!".format(enemy["name"], enemydmg))
if player["hp"] <= 0:
print()
print("The {0} has killed you!".format(enemy["name"]))
break