Commit 005262d8 by BellCodeEditor

auto save

parent b70de0c0
Showing with 30 additions and 13 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=250
self.attack = 40 self.attack=40
self.name = name self.name=name
def combat(self,hero_): # 攻击 def combat(self,hero_):
hero_.hp-=hero_.attack print('-'*50)
hero_.hp-=self.attack
s1=self.name+'对'+hero_.name+'发起了攻击,' s1=self.name+'对'+hero_.name+'发起了攻击,'
s2=hero_.name+'血量-'+str(self.attack)+',' s2=hero_.name+'hp-'+str(self.attack)+','
s3=hero_.name+'血量:'+str(hero_.hp)+'。' if hero_.hp > 0:
s=s1+s2+s3 s3=hero_.name+'hp:'+str(hero_.hp)+'。'
print(s) s=s1+s2+s3
print(s)
else:
s3=hero_.name+'阵亡,游戏结束!'
s=s1+s2+s3
print(s)
exit()
print('-'*50)
class Player:
def __init__(self,name):
super()__init__(level,name)
self.hp=200
self.attack=50
yase = Hero("垭瑟") yase = Hero("垭瑟")
houyi= Hero("后羿") houyi= Hero("后羿")
yase.combat(houyi) player=Player('后羿')
\ No newline at end of file yase.combat(houyi)
print(player.hp)
\ 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