Commit 6180921d by BellCodeEditor

save project

parent 381545d6
Showing with 19 additions and 12 deletions
# 英雄角色类 # 英雄角色类
class Hero(object): class Hero(object):
def __init__(self, name): def __init__(self,level,hp,attack,name):
self.level = level self.level = level
self.hp = hp self.hp = hp
self.attack = attack self.attack = attack
self.name = name self.name = name
def combat(self,enamy):
def combat(self,enamy): info1=self.name+"对"+enamy.name+"发起进攻"
info1=self.name+"对"+enamy.name+"发起进攻" enamy.attack-=self.attack
enamy.attack-=self.attack info2=self.name+"对"+enamy.name+"造成"+str(self.attack)+"点伤害"
info2=self.name+"对"+enamy.name+"造成"+str(self.attack)+"点伤害,"+enamy.name+"剩"+str(enamy.attack) if enamy.hp>0:
if enamy.attack==0: info3=enamy.name+"剩"+str(enamy.attack)+"生命值"
in info=info1+info2+info3
print(info)
else:
info3="游戏结束"+enamy.name+"阵亡"
info=info1+info2+info3
print(info)
yase = Hero(5,1000,500",垭瑟")
houyi= Hero(5,100,50",后羿") yase = Hero(5,1000,500,"垭瑟")
yase.combat(houyi) houyi= Hero(5,100,50,"后羿")
\ No newline at end of file yase.combat(houyi)
houyi.combat(yase)
\ 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