获得NameError: name 'cost' is not defined at player.reduce_mp(cost)
elif index == 1:
player.choose_magic()
magic_choice = int(input('Choose magic'))-1
magic_dmg = player.generate_spell_damage()
spell = player.get_spell_name(magic_choice)
cost = player.get_spell_mp_cost(magic_choice)
current_mp = player.get_mp()
if cost > current_mp:
print(bcolors.FAIL + '\nNot enough MP\n' + bcolors.ENDC)
continue
player.reduce_mp(cost)
enemy.take_damage(magic_dmg)
print(bcolors.OKBLUE + '\n' + spell + 'deals', str(magic_dmg), 'points of damage' + bcolors.ENDC)
答案 0 :(得分:0)
现在怎么样:
elif index==1:
player.choose_magic()
magic_choice=int(input('Choose magic'))-1
magic_dmg=player.generate_spell_damage()
spell=player.get_spell_name(magic_choice)
cost=player.get_spell_mp_cost(magic_choice)
current_mp=player.get_mp()
if cost>current_mp:
print(bcolors.FAIL+ '\nNot enough MP\n'+bcolors.ENDC)
continue
player.reduce_mp(cost)
enemy.take_damage(magic_dmg)
print(bcolors.OKBLUE+'\n'+spell+'deals',str(magic_dmg),'points of damage'+bcolors.ENDC)
答案 1 :(得分:-1)