Commit 3afe9f5e by BellCodeEditor

save project

parent 9a581ef4
Showing with 54 additions and 7 deletions
# 英雄角色类
class Hero(object): class Hero(object):
def __init__(self, name): def __init__(self,name):
self.level = 1 self.level = 1
self.hp = 250 self.hp = 300
self.attack = 40 self.attack = 50
self.name = name self.name = name
def combat(): # 攻击 def combat(self,enemy):
??? enemy.hp -= self.attack
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害,"
if enemy.hp > 0:
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
infoa = info1 + info2 + info3
print(infoa)
else:
info4 = enemy.name + "阵亡,游戏结束"
infob = info1 + info2 + info4
print(infob)
exit()
yase = Hero("垭瑟") yase = Hero("垭瑟")
houyi= Hero("后羿") houyi= Hero("后羿")
yase.combat(houyi) yase.combat(houyi)
\ No newline at end of file
class Hero:
def __init__(self,name,hp,attack):
self.level = 1 #等级
self.name = name #名字
self.hp = hp #血量
self.attack = attack #攻击力
def upgrade():
#垭瑟升级
yase.level=yase.level+1
yase.hp=yase.hp+50
yase.attack=yase.attack+5
#后艺升级
houyi.level=houyi.level+1
houyi.hp=houyi.hp+50
houyi.attack=houyi.attack+5
#百里玄策升级
bailidi.level=bailidi.level+1
bailidi.hp=bailidi.hp+50
bailidi.attack=bailidi.attack+5
#百里守约升级
bailige.level=bailige.level+1
bailige.hp=bailige.hp+50
bailige.attack=bailige.attack+5
yase = Hero("垭瑟",300,20)
houyi = Hero("后艺",250,23)
bailidi = Hero("百里玄策",225,30)
bailige = Hero("百里守约",245,25)
upgrade()
print("垭瑟的血量为:",yase.hp,",垭瑟的攻击力为:",yase.attack)
print("后艺的血量为:",houyi.hp,",后艺的攻击力为:",houyi.attack)
print("百里玄策的血量为:",bailidi.hp,",百里玄策的攻击力为:",bailidi.attack)
print("百里守约的血量为:",bailige.hp,",百里守约的攻击力为:",bailige.attack)
\ 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