# 父类
class baba():
def run(self):
print("跑啊")
def pu_gong(self):
print("普攻")
# 心中英雄类
class Jiangwei(baba):
def __init__(self):
self.name = "姜维"
self.__hp = 2978 # 属性名前加两个下划线,隐藏属性
self.fa_li_zhi = 0
self.gong_ji_li = 182
self.fang_yu = 102
def cha_kan_hp(self):
print(self.__hp)
def xiu_gai(self, new_hp):
"""new_hp: 传入新的血量值"""
"""self.__hp:影响本身血量 """
self.__hp = new_hp
if new_hp > 12000:
self.__hp = 0.1
print("您因*##*被封号,请您死后再登陆!!")
def bei_dong_ji_neng(self):
print("幼麟")
print('每普攻十五次,召唤出幼麟造成物理攻击10%的法术伤害')
def ji_neng1(self):
print("智勇双全 ")
def ji_neng2(self):
print("破阵")
def ji_neng3(self):
print("八卦阵·继承")
def __str__(self):
return "我是姜维,我的血量%f" % self.__hp
def run(self):
print("飞啊")
class Yase(baba):
# 属性 魔法方法
def __init__(self):
self.name = "亚瑟"
self.hp = 3306
self.fa_li_zhi = 0
self.gong_ji_li = 164
self.fang_yu = 98
# 方法
def ji_neng1(self):
print(self.name)
print("契约神盾")
def ji_neng2(self):
print("回旋打击")
def ji_neng3(self):
print("圣剑裁决")
# 对象名 = 类名
jiang = Jiangwei()
jiang.bei_dong_ji_neng()
# print(jiang.__hp)
# jiang.hp += 1000
# print(jiang.hp)
# jiang.hp += 100000000000000
# print(jiang.hp)
# dota2
jiang.ji_neng1()
jiang.cha_kan_hp()
jiang.xiu_gai(123232253645)
jiang.cha_kan_hp()
print(jiang)
jiang.run()
xingtai - 类与对象
最新推荐文章于 2024-03-22 09:52:36 发布