Commit 6176055c by BellCodeEditor

save project

parent 9a581ef4
Showing with 38 additions and 15 deletions
# 英雄角色类 class Hero():
class Hero(object): def __init__(self,name,hp,attack,level):
def __init__(self, name): self.name=name
self.level = 1 self.level=level
self.hp = 250 self.hp=hp
self.attack = 40 self.attack=attack
self.name = name def Up_level(self,up):
self.level=self.level+up
def combat(): # 攻击 self.hp=self.hp+up*50
??? self.attack=self.attack+up*4
def combat(self,enemy):
yase = Hero("垭瑟") print("战斗开始")
houyi= Hero("后羿") print("-"*50)
yase.combat(houyi) info1=self.name+"对"+enemy.name+"发起进攻,"
\ No newline at end of file info2="造成了"+str(self.attack)+"点伤害,"
enemy.hp=enemy.hp-self.attack
if enemy.hp > 0:
info3=enemy.name+"还剩下"+str(enemy.hp)+"点血量"
info=info1+info2+info3
print(info)
print("-"*50)
else:
info3=enemy.name+"还剩下"+str(enemy.hp)+"点血量"
info=info1+info2+info3
print(info)
print("-"*50)
exit()
yase = Hero("垭瑟",300,20,1)
houyi = Hero("后羿",250,23,1)
print("垭瑟升级前攻击:",yase.attack)
print("垭瑟升级前血量:",yase.hp)
print("垭瑟升级前等级:",yase.level)
yase.Up_level(1)
print("-"*50)
print("垭瑟升级后攻击:",yase.attack)
print("垭瑟升级后血量:",yase.hp)
print("垭瑟升级后等级:",yase.level)
\ 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