Commit b9e0cfc6 by BellCodeEditor

save project

parent 9a581ef4
Showing with 17 additions and 5 deletions
# 英雄角色类 # 英雄角色类
class Hero(object): class Hero(object):
def __init__(self, name): def __init__(self,attack,hp,level,name):
self.level = 1 self.level = 1
self.hp = 250 self.hp = 250
self.attack = 40 self.attack = 40
self.name = name self.name = name
def combat(): # 攻击 def combat(self,enermy):
??? enermy.hp-=self.attack
if enermy.hp>0:
info1=self.name+"对"+enermy.name+"发动了攻击\n"
info2=enermy.name+"血量降低了"+str(self.attack)+"\n"
info3=enermy.name+"还剩余"+str(enermy.hp)+"点的血量\n"
print(info1+info2+info3)
else:
info1=self.name+"对"+enermy.name+"发动了攻击\n"
info2=enermy.name+"血量降低了"+str(self.attack)+"\n"
info3=enermy.name+"还剩余"+str(enermy.hp)+"点的血量\n"
print(info1+info2+info3)
print(enermy.name+"嗝屁了")
yase = Hero("垭瑟") yase = Hero(50,200,1,"垭瑟")
houyi= Hero("后羿") houyi= Hero(60,190,1,"后羿")
yase.combat(houyi) yase.combat(houyi)
\ 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