在下面,我有一个代码怪物。
def battle(oppatk, oppdef, opphealth, oppeva, oppspe, oppname):
var1 = 0
while True:
if var1 > 0:
if speed > oppspe:
playerattack(oppdef, playerattack(oppdef, opphealth, oppeva, oppname), oppeva, oppname)
opponentattack(oppatk, opponentattack(oppatk, health, defense, oppname, evasion), defense, oppname, evasion)
elif oppspe > speed:
opponentattack(oppatk, opponentattack(oppatk, health, defense, oppname, evasion), defense, oppname, evasion)
playerattack(oppdef, playerattack(oppdef, opphealth, oppeva, oppname), oppeva, oppname)
else:
aaa = random(0, 1)
if aaa == 0:
opponentattack(oppatk, opponentattack(oppatk, health, defense, oppname, evasion), defense, oppname, evasion)
playerattack(oppdef, playerattack(oppdef, opphealth, oppeva, oppname), oppeva, oppname)
else:
playerattack(oppdef, playerattack(oppdef, opphealth, oppeva, oppname), oppeva, oppname)
opponentattack(oppatk, opponentattack(oppatk, health, defense, oppname, evasion), defense, oppname, evasion)
基本上发生的事情是它经历了游戏片和对手攻击功能,取决于哪个更快,玩家或对手。但是,当我调用其返回值的其中一个函数在下次运行时使用时,它会改为执行某种子级代码而不会对程序产生实际影响。您如何编写代码来避免这种情况?