Commit d9be9fce by BellCodeEditor

auto save

parent ee97dcbd
Showing with 19 additions and 6 deletions
......@@ -3,12 +3,25 @@ class Hero(object):
def __init__(self, name):
self.level = 1
self.hp = 250
self.attack = 40
self.attack = 20
self.name = name
def combat(): # 攻击
???
def combat(self,enemy): # 攻击
info1=self.name+'对'+enemy.name+'发起进攻'+'造成'+str(self.attack)+'点伤害'
enemy.hp-=self.attack
if enemy.hp>0:
info2=enemy.name+'还剩下'+str(enemy.hp)+'血量'
info=info1+info2
print(info)
else:
info2=enemy.name+'已阵亡,游戏结束'
info=info1+info2
print(info)
exit()
yase = Hero("垭瑟")
houyi= Hero("后羿")
yase.combat(houyi)
\ No newline at end of file
yase.combat(houyi)
houyi.combat(yase)
#当调用combat()时,可以输出"xxxx对xxx发起进攻,造成xx点伤害,xxx还剩下x血量"
#发动攻击后,当被攻击者的血量大于0,则输出:xxx对xx发起进攻,造成x点伤害
#xx还剩下x血量当被攻击者的血量小于等于0,则输出:xx对xx发起进攻造成x点伤害,xx阵亡,游戏结束
\ 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