2017-09-25 32 views

回答

1

如果您正在尋找一種通用方法,我會建議構建一個查找字典,如下所示。你可以用這本字典來計算損壞程度,

def get_damage(enemy_type,weapon): 
    damage_dict = {"enemy_type1":{'weapon1':10,'weapon2':20,'weapon3':50}, 
        "enemy_type2":{'weapon1':5,'weapon2':20,'weapon3':45}, 
        "enemy_type3":{'weapon1':15,'weapon2':20,'weapon3':40,'weapon4':50}, 
        } 
    return damage_dict.get(enemy_type).get(weapon) 

print(get_damage('enemy_type2','weapon2')) 
相關問題