Commit 005262d8 by BellCodeEditor

auto save

parent b70de0c0
Showing with 30 additions and 13 deletions
# 英雄角色类
class Hero(object):
def __init__(self, name):
self.level = 1
self.hp = 250
self.attack = 40
self.name = name
def __init__(self,name):
self.level=1
self.hp=250
self.attack=40
self.name=name
def combat(self,hero_): # 攻击
hero_.hp-=hero_.attack
def combat(self,hero_):
print('-'*50)
hero_.hp-=self.attack
s1=self.name+'对'+hero_.name+'发起了攻击,'
s2=hero_.name+'血量-'+str(self.attack)+','
s3=hero_.name+'血量:'+str(hero_.hp)+'。'
s=s1+s2+s3
print(s)
s2=hero_.name+'hp-'+str(self.attack)+','
if hero_.hp > 0:
s3=hero_.name+'hp:'+str(hero_.hp)+'。'
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("垭瑟")
houyi= Hero("后羿")
yase.combat(houyi)
\ No newline at end of file
player=Player('后羿')
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