如何在python中将max()的值设置为变量

时间:2021-06-21 16:19:55

标签: python random max

我正在尝试制作一个非常简单的回合制游戏来练习 Python,其中有一个 Troll 和一个 Player 互相攻击,并且确定该回合中谁先攻击的方式由随机函数确定?如果随机是一个函数。所以我遇到了这个问题,一旦掷出“骰子”,就会有一个 if else satment 来确定谁先攻击,基于 max() 函数来选择更高的 Initiitive 分数,我不知道如何设置变量的值等于 max()。完整代码如下:

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} ')

0 个答案:

没有答案
相关问题