Commit b7cf1b3c by BellCodeEditor

save project

parent ce44dbd8
Showing with 46 additions and 0 deletions
class Hero():
def __init__(self,name):
self.name=name
self.level=1
self.hp=250
self.attack=20
def Up_level(self,up):
self.level=self.level+up
self.hp=self.hp+up*50
self.attack=self.attack+up*4
def combat(self,enemy):
print("战斗开始")
print("-"*50)
info1=self.name+"对"+enemy.name+"发起进攻,"
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+"阵亡,游戏结束"
info=info1+info2+info3
print(info)
print("-"*50)
exit()
class Player(Hero):
def __init__(self,name):
super().__init__(name)
self.hp=200
self.attack=50
# yase = Hero("垭瑟",300,50,1)
player = Player("垭瑟")
houyi = Hero("后羿")
# print("垭瑟升级前攻击:",yase.attack)
# print("垭瑟升级前血量:",yase.hp)
# print("垭瑟升级前等级:",yase.level)
# yase.Up_level(1)
# print("-"*50)
# print("垭瑟升级后攻击:",yase.attack)
# print("垭瑟升级后血量:",yase.hp)
# print("垭瑟升级后等级:",yase.level)
print("-"*50)
player.combat(houyi)
\ 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