I want the following code to generate different outputs from the battle() function which should appear at the end of a script. I managed to do this but the outputs are all the same. What did i wrong?
import math
import random
def storage():
global get_evasion
global get_weapon
get_evasion = 0
get_weapon = 0
storage()
def battle():
for c in range(24):
for _ in range(5):
if monsterChoice.hp > 0:
global monster_dmg
m_chance_1 = [1] * int(m_hitChance)
m_miss = 100 - int(m_hitChance)
m_chance_0 = [0] * int(m_miss)
x = (int(random.choice(m_chance_1 + m_chance_0)))
if x == 1 and p1.hp > 0:
monster_dmg = monsterChoice.atk_power - random.randint(
1, 5 * monsterChoice.level) - p1.defence
if monster_dmg < 0: monster_dmg = 0
p1.hp -= monster_dmg
print('You were dealt ' + str(monster_dmg) + ' DMG. ' +
str(p1.hp) + ' HP LEFT')
if x == 0:
global get_evasion
get_evasion += 1
print('You evaded this attack! ')
elif x == 0 or x == 1 and p1.hp < 0:
print('YOU ARE DEAD!')
for _ in range(1):
if monsterChoice.hp > 0:
global player_dmg
p_chance_1 = [1] * int(p_hitChance)
p_miss = 100 - int(p_hitChance)
p_chance_0 = [0] * int(p_miss)
x = (int(random.choice(p_chance_1 + p_chance_0)))
if x == 1 and monsterChoice.hp > 0:
player_dmg = int(p1.atk_power +
random.randint(1, 5 * p1.level) -
monsterChoice.defence)
if player_dmg < 0: player_dmg = 0
global get_weapon
if player_dmg >= 1: get_weapon += 1
monsterChoice.hp -= player_dmg
print('You deal ' + str(player_dmg) + ' DMG. ' +
str(monsterChoice.hp) + ' HP LEFT')
if x == 0:
print('You missed! ')
if monsterChoice.hp < 0:
print('YOU WON THE BATTLE!')
return (get_weapon, get_evasion)
battle()
if p1.evasion in range(2000, 5000): get_evasion /= 360
get_weapon /= 100
print(get_evasion)
print(get_weapon)
if monsterChoice.hp > 0 and p1.hp > 0:
print('DRAW!. You get ' + str(get_weapon) + ' weapon skill and ' +
str(get_evasion) + ' evasion skill')
weapon_results, evasion_results = [], []
for k in range(2):
get_weapon, get_evasion = battle()
weapon_results.append(get_weapon)
evasion_results.append(get_evasion)
print(evasion_results)
What I get is:
YOU WON THE BATTLE! 0.25 0.08 [0.25, 0.25]
These last 2 values should be random with each iteration
Aucun commentaire:
Enregistrer un commentaire