Commit 12a9b18f by BellCodeEditor

auto save

parent cf4e99dd
Showing with 10 additions and 10 deletions
...@@ -5,13 +5,13 @@ class Hero: # 类名,Hero表示英雄 ...@@ -5,13 +5,13 @@ class Hero: # 类名,Hero表示英雄
self.hp = hp # 生命(类属性) self.hp = hp # 生命(类属性)
self.attack = attack # 攻击力(类属性) self.attack = attack # 攻击力(类属性)
def ypgrade(): # 用关键字def定义方法名,封装函数 def upgrade(self): # 函数封装
yase.level=yase.level+1 # 每升级一次等级+1 self.level = self.level + 1 # 每升级一次等级+1
yese.hp=yase.hp+50 # 。。。。 血量+50 self.hp = self.hp + 50 # 。。。。 血量+50
yase.attack=yase.attack+4 # 。。。。 攻击力+4 self.attack = self.attack + 4 # 。。。。 攻击力+4
yase = Hero("亚瑟",300,20) # 括号内实参123分别对应形参123 houyi = Hero("后羿",240,23) # 括号内实参123分别对应形参123
print("亚瑟的初始血量为: ",yase.hp) houyi.upgrade() # 用角色名的方法调用函数,下面依次查看属性值
upgrade() # 重复调用函数 print("等级为: ",houyi.level)
upgrade() # 重复调用函数 print("血量为: ",houyi.hp)
print("升级2次后,亚瑟的血量为: ",yase.hp) print("攻击力为: ",houyi.attack)
\ No newline at end of file \ 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