我有一个名为攻击的函数:
def attack(name,minmultiplier,maxmultiplier,critchance,attacker,attackee):
print(attacker[0],"used",name)
multiplier=random.randint(minmultiplier,maxmultiplier)
crit=random.randint(critchance,100)
if crit==100 and ((attacker[2]*multiplier*2)-attackee[3]) > 0:
attackee[1]=attackee[1]-((attacker[2]*multiplier*2)-attackee[3])
elif ((attacker[2]*multiplier)-attackee[3]) > 0:
attackee[1]=attackee[1]-((attacker[2]*multiplier)-attackee[3])
else:
print("You fail to hit",attackee[0])
print(attackee[0],"'s health after",attacker[0],"'s attack is",attackee[1])
我在这里对老板和玩家进行了一些实际的攻击:
boss=["Greed",1000,10,10,1]
slashp=attack("slash",1,2,5,player,boss)
slashb=attack("slash",1,2,5,boss,player)
kick=attack("kick",1,1,1,player,boss)
aiattacklist=[slashb]
attacknamelist=["slash","kick"]
attackfunclist=[slashp,kick]
即使我只是将这些版本保存为变量,它们仍然被调用:
template used slash
You fail to hit Greed
Greed 's health after template 's attack is 1000
Greed used slash
template 's health after Greed 's attack is 58
template used kick
You fail to hit Greed
Greed 's health after template 's attack is 1000
这是python总是做的事情,还是我做错了什么,因为我不希望这些被调用(对不起,如果我没有使用正确的术语,我有点新)