Commit 5477adb8 by BellCodeEditor

auto save

parent 9a581ef4
Showing with 39 additions and 4 deletions
...@@ -6,9 +6,43 @@ class Hero(object): ...@@ -6,9 +6,43 @@ class Hero(object):
self.attack = 40 self.attack = 40
self.name = name self.name = name
def combat(): # 攻击 def combat(self,dr): # 攻击
??? '''
我方英雄对敌方英雄进行攻击,
yase = Hero("垭瑟") 1.敌方英雄hp(???)减少 减少的是我方英雄攻击力(???)的点数
2.输出提示信息
2.1我方英雄(???) 对 敌方英雄(???) 进行了攻击,
2.2造成了 我方英雄攻击力(???) 点伤害,
3.判断 敌方英雄hp(???) 小于等于 0
3.1判断成立,代表敌方英雄阵亡, 敌方英雄(???) 已阵亡
3.2判断不成立, 游戏继续 敌方英雄(???)还剩 多少(???)点血量
'''
dr.hp -= self.attack #dr.hp = dr.hp - self.attack
i1 = self.name + "对" + dr.name + "进行了攻击,"
i2 = "造成了" + str(self.attack) + "点伤害,"
if dr.hp <= 0:
i3 = dr.name + "已阵亡,游戏结束"
print(i1+i2+i3)
exit()
else:
i3 = dr.name + "还剩" + str(dr.hp) + "点血量"
print(i1+i2+i3)
class player(Hero):
def __init__(self, name,herotype):
super().__init__(name)
self.hp = 600
self.attack = 70
self.herotype = herotype
s1 = "玩家英雄:" + self.name + ",创建完成,祝您游戏愉快!"
s2 = "英雄定位:" + self.herotype +"hp,attack分别为:"+str(self.hp)+","+str(self.attack)
print(s1)
print(s2)
yase = player("垭瑟","战士")
houyi= Hero("后羿") houyi= Hero("后羿")
yase.combat(houyi) yase.combat(houyi)
'''
子类会继承父类的所有方法和属性
可以修改里边的属性和方法
为了避免重复继承导致的问题,需要使用super函数
'''
\ 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