Commit 76db49c3 by BellCodeEditor

auto save

parent 9a581ef4
Showing with 15 additions and 7 deletions
# 英雄角色类 # 英雄角色类
class Hero(object): class Hero(object):
def __init__(self, name): def __init__(self, name,hp,attack):
self.level = 1 self.level = 1
self.hp = 250 self.hp = hp
self.attack = 40 self.attack = attack
self.name = name self.name = name
def combat(): # 攻击 def combat(self,qita): # 攻击
??? qita.hp=qita.hp-self.attack
info1=self.name+'对'+qita.name+'造成了'+str(self.attack)+'点生命。'
if qita.hp>0:
info2=qita.name+'还剩下'+str(qita.hp)+'点生命.'
else:
info2=qita.name+'已经死亡。'
info=info1+info2
print(info)
yase = Hero("垭瑟") yase = Hero("垭瑟",200,40)
houyi= Hero("后羿") houyi= Hero("后羿",160,60)
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