Commit 3b022ca7 by BellCodeEditor

save project

parent c0183cee
Showing with 12 additions and 6 deletions
...@@ -5,15 +5,20 @@ class Hero(object): ...@@ -5,15 +5,20 @@ class Hero(object):
self.hp = hp self.hp = hp
self.attack = attack self.attack = attack
self.name = name self.name = name
def combat(self,enemy): def combat(self,enemy):
info1=self.name+"对"+enemy.name+"发起进攻," info1=self.name+"对"+enemy.name+"发起进攻,"
info2="造成"+str(self.attack)+"点伤害," info2="造成"+str(self.attack)+"点伤害,"
enemy.hp-=self.attack enemy.hp-=self.attack
if enemy.name if enemy.hp>0:
info3=enemy.name+"剩余血量为"+str(enemy.hp)+"点。"
info=info1+info2+info3
yuange = Hero(5,750,87,"元歌") print(info)
shouyue= Hero(5,700,50,"守约") else:
info3=enemy.name+"阵亡,游戏结束"
info=info1+info2+info3
print(info)
exit()
yuange = Hero(5,3050,670,"元歌")
shouyue= Hero(5,3000,676,"守约")
yuange.combat(shouyue) yuange.combat(shouyue)
shouyue.combat(yuange) shouyue.combat(yuange)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment