samedi 8 février 2020

Trying to write DnD combat script in python, need help printing enemy HP after dice roll

I'm new to coding, so if I make a careless mistake sorry in advance.

I'm trying to write a DnD (specifically, a Star Wars Knights of the Old Republic) combat script. Basically, whenever you attack the game rolls a 20 sided die and if the result is greater than the enemy's defense, you do a successful hit.

Here, I've created a script that does basically that. I am, however, having problems printing the enemy's HP. Instead of remembering the last number and continuing to subtract the damage till the enemy's HP reaches 0, the script keeps on subtracting it from 30 every time, so every roll I get a different number.

How would I make the program remember the HP values and subtract the damage from them accordingly?

import random

dice_min = 1
dice_max = 20

defense = 10
attack_bonus = 3

player_vitality = 30
enemy_vitality = 30

running = True

while running == True:

dice_roll = random.randint(dice_min, dice_max)

attack_roll = dice_roll + attack_bonus

enemy_damage = enemy_vitality - attack_roll

attack_prompt = input("Do you want to attack? [y/n]: ")

if attack_roll > defense:
    print("successful hit, the enemy's health is now " + str(enemy_damage))
elif attack_roll < defense:
    print("you missed, the enemy's health is " + str(enemy_damage))



Aucun commentaire:

Enregistrer un commentaire