class pokemon(object):
attack_dict = {'fire':{'fire':0.75,'grass':1.5,'water':0.75},
'grass':{'fire':0.75,'grass':0.75,'water':1.5},
'water':{'fire':1.5,'grass':0.75,'water':0.75},}
def __init__(self, name, hp, attack, type):
self.name = name #名称
self.hp = hp #血量
self.attack = attack #攻击力
self.type = type #属性
def Battle(self , enemy):
damage = self.attack * self.attack_dict[self.type][enemy.type]
#伤害 = 攻击力*属性克制 (在自己的属性字典中搜索敌人属性的倍率)
if(self.hp > 0): #血量不归零继续战斗
enemy.hp -= damage # 根据伤害减去对面血量
print("%s 对 %s造成了 %s 点伤害"%(self.name,enemy.name,damage))
print("%s剩余%s血量"%(enemy.name,enemy.hp))
return enemy.Battle(self) #对方反击,回合制互殴
else:
print("%s赢得了这场战斗,剩余血量%s"%(enemy.name,enemy.hp))
return enemy,self #返回一个元组(winner,loser)
xiaohuolong = pokemon('小火龙',90,7,'fire')
jienigui = pokemon('杰尼龟',100,6,'water')
miaowazongzi = pokemon('妙蛙种子',120,5,'grass')
xiaohuolong.Battle(miaowazongzi)
02-03
03-05
400