Commit 15abf23e by BellCodeEditor

auto save

parent 5b7bd3c2
Showing with 2 additions and 8 deletions
#通过函数使角色等级增加时其他效果一起增加
class Hero:#定义一个类 class 类名: class Hero:#定义一个类 class 类名:
    def __init__(self,name,hp,attack):#多加几个形参     def __init__(self,name,hp,attack):#多加几个形参
        self.level = 1#定义形参,定义成自己         self.level = 1#定义形参,定义成自己
...@@ -6,10 +5,5 @@ class Hero:#定义一个类 class 类名: ...@@ -6,10 +5,5 @@ class Hero:#定义一个类 class 类名:
        self.attack = attack         self.attack = attack
yase = Hero("亚瑟",300,40)#name是"亚瑟",hp,attack是300,40 yase = Hero("亚瑟",300,40)#name是"亚瑟",hp,attack是300,40
houyi = Hero("后羿",300,40)#按def __init__的方法里形参的顺序挨个写具体值(实参) houyi = Hero("后羿",300,40)#按def __init__的方法里形参的顺序挨个写具体值(实参)
def 增值(): print(yase.hp)#打印yase的参数
yase.level = yase.level + 1 print(houyi.hp)
yase.hp = yase.hp + 20
yase.attack = yase.attack + 100
print(yase)
增值()
print(houyi)
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