diff --git a/diy1.py b/diy1.py index e432e0e..1042ed4 100644 --- a/diy1.py +++ b/diy1.py @@ -8,7 +8,12 @@ class Hero(object): def combat(self,a): # 攻击 a.hp=a.hp-self.attack - print('%s对%s发起攻击,造成%s伤害,%s还剩下%s血量'%(self.name,a.name,self.attack,a.name,a.hp)) + if a.hp>0: + print('%s对%s发起攻击,造成%s伤害,%s还剩下%s血量'%(self.name,a.name,self.attack,a.name,a.hp)) + else: + print('%s阵亡'%(a.name)) + exit() yase = Hero("垭瑟") houyi= Hero("后羿") -yase.combat(houyi) \ No newline at end of file +for i in range(100): + yase.combat(houyi) \ No newline at end of file