Commit 5fd1d5b4 by BellCodeEditor

auto save

parent f47689a4
Showing with 35 additions and 0 deletions
class Hero:
def __init__(self,name,hp,attack):
self.level = 1 #等级
self.name = name
self.hp = hp #血量
self.attack = attack #攻击力
#属性升级
def upgrade(self):
self.level += 1
self.hp += 50
self.attack += 5
#实例化对象
houyi = Hero('后羿',240,25)
yase = Hero('亚瑟',400,18)
zhaoyun = Hero('赵云',300,22)
machao = Hero('马超',300,24)
huangzhong = Hero('黄忠',260,20)
daji = Hero('妲己',200,70)
houyi.upgrade()
print('后羿的属性值是:',houyi.level,houyi.hp,houyi.attack)
print('亚瑟的属性值是:',yase.level,yase.hp,yase.attack)
zhaoyun.upgrade()
print('赵云的属性值是:',zhaoyun.level,zhaoyun.hp,zhaoyun.attack)
print('马超的属性值是:',machao.level,machao.hp,machao.attack)
huangzhong.upgrade()
print('黄忠的属性值是:',huangzhong.level,huangzhong.hp,huangzhong.attack)
print('妲己的属性值是:',daji.level,daji.hp,daji.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