Commit 2b7e7b2d by BellCodeEditor

save project

parent ce3aea01
Showing with 14 additions and 9 deletions
class Hero(): class Hero():
def __init__(self,hp,defense,attck): def __init__(self,name):
self.level=1 self.level=1
self.hp=hp self.hp=1229
self.defense=defense self.defense=257
self.attck=attck self.attck=249
self.name=name
Chen = Hero(1229,257,249)
Hoshiguma = Hero(1602,154,221)
def comboat(self,enemy): def comboat(self,enemy):
enemy.hp-=self.attck-self.defense
info1=self.name+"对"+enemy.name+"发起攻击," info1=self.name+"对"+enemy.name+"发起攻击,"
info2="造成"+str(self.attck)+"的伤害," info2="造成"+str(self.attck)+"的伤害,"
if self.enemy>0: enemy.hp-=self.attck-self.defense
if enemy.hp>0:
info3=enemy.name+"还剩下"+str(enemy.hp)+"血量" info3=enemy.name+"还剩下"+str(enemy.hp)+"血量"
info=info1+info2+info3 info=info1+info2+info3
print(info) print(info)
else: else:
info3=enemy.name+"阵亡,游戏结束" info3=enemy.name+"阵亡,游戏结束"
print(info3)
exit() exit()
Chen=Hero("陈")
Hoshiguma=Hero("星熊")
Chen.comboat(Hoshiguma)
\ 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