Commit b9ca7a03 by BellCodeEditor

save project

parent 4c565b93
Showing with 18 additions and 13 deletions
class Hero:
def __init__(self,name,hp,attack):
self.level=1
self.name=name
self.hp=hp
self.attack=attack
yase=Hero('yase',300,20)
hy=Hero('hy',250,23)
k=Hero('K',5600,199)
print(yase.attack)
print(hy.attack)
print(k.attack)
\ No newline at end of file
class Hero: #创建类
def __init__(self,name,hp,attack): #定义一个方法
self.level = 1 #等级为1
self.name = name #英雄的名字
self.hp = hp #英雄的血量
self.attack = attack #英雄的攻击力
def uprade(self): #定义一个升级函数
self.level += 1 #等级+1
self.hp += 50 #血量+50
self.attack += 5 #攻击力+5
houyi = Hero('后羿',240,23) #创建houyi英雄
houyi.uprade() #houyi升级
print('等级:',houyi.level) #等级为...
print('血量:',houyi.hp) #血量为...
print('攻击力:',houyi.attack) #攻击力为...
\ 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