I was trying to make a very simple turn based game to practice Python, where there is a Troll and a Player that attack each other, and the way to determine who attacks first in that round is determined by a random function? If random is a function. So I've had this problem where once rolled the "Dices" there is an if else satment that determines who attacks first, based on a max() function to select the higher score of Initaitive, and I don't know how to set the value of the variable equal to the max(). Here is the full code:
import random
turn = 0
troll_health = 50
troll_status_effect = None
troll_damage = random.randint(1, 5)
troll_initiative = (random.randint(1, 10)) + 3
player_health = 30
player_damage = random.randint(5, 10)
player_initiative = (random.randint(1, 10)) + 5
start_fight = input('Do you want to start the combat?')
while start_fight == 'yes':
attacks_first = max(player_initiative, troll_initiative)
if attacks_first == player_initiative: # This is where I think that the problem is
action = input('What do you do?')
if action == 'attack' and (random.randint(1, 20) + 5) > 10:
troll_health -= player_damage
print(f'You take the troll {player_damage} points of damage.')
else:
print('You missed')
else:
if (random.randint(1, 20) + 2) > 13:
player_health -= troll_damage
print(f'The troll attacks, and now you have {player_health} ')
Aucun commentaire:
Enregistrer un commentaire