Commit 9869834a by BellCodeEditor

auto save

parent ec55c037
Showing with 8 additions and 6 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#定义形参,定义成自己
...@@ -5,9 +6,10 @@ class Hero:#定义一个类 class 类名: ...@@ -5,9 +6,10 @@ 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__的方法里形参的顺序挨个写具体值(实参)
print(yase.hp)#打印yase的参数 def 增值():
print(yase.hp)#打印yase的参数 yase.level = yase.level + 1
a = yase.hp+1 yase.hp = yase.hp + 20
print(a) yase.attack = yase.attack + 100
def aio(): 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