I have a text adventure game with battle system in place already. It is of course turn based, both player and enemy deal damage points (in float). I use random.uniform() function to generate attack points for every round.
Zero stands for missing an enemy or player. However since I use floats that chance is pretty slim. I want to create a condition where there would be let's say a chance 1 in 5 that attack points equal 0.00. This condition must be run on every round.
How would I go about it? Is there a module I could use?
note: I think I could use random module (random.randint(0,5)) but I was wondering if there is some other way. Thanks!
I think you should use random.uniform() reserving 20% of values for 0.00 attack points.
hit = random.uniform(0, 10)
if hit <= 2:
damage = 0.00
else:
damage = (hit - 2) / 8
This is just a stupid example but might help. Or even more simple:
hit = random.uniform(0, 10)
if hit >= 8:
damage = 0.00
else:
damage = hit / 8
I'd suggest rolling two random numbers: One for the chance to hit and another for the actual damage dealt. You could also combine them with player attributes. Example:
if random.uniform(0, 100) < player.chance_to_hit:
damage = random.uniform(weapon.min_damage, weapon.max_damage)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With