Commit 6180921d by BellCodeEditor

save project

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