Commit b9ca7a03 by BellCodeEditor

save project

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