Commit a3b53b0e by BellCodeEditor

save project

parent 4994250d
Showing with 10 additions and 4 deletions
# 英雄角色类 import random()
class Hero(object): class Hero(object):
def __init__(self, name): def __init__(self, name):
self.level = 1 self.level = 1
...@@ -9,10 +9,16 @@ class Hero(object): ...@@ -9,10 +9,16 @@ class Hero(object):
def combat(self,duifang): # 攻击 def combat(self,duifang): # 攻击
duifang.hp-=self.attack duifang.hp-=self.attack
if duifang.hp>0: if duifang.hp>0:
print(self.name+"对"+duifang.name+"发起攻击,"+duifang.name+"减少"+self.attack+"血量,"+duifang.name+"还剩"+duifang.hp+"血量") print(self.name+"对"+duifang.name+"发起攻击,"+duifang.name+"减少"+str(self.attack)+"血量,"+duifang.name+"还剩"+str(duifang.hp)+"血量")
else: else:
print(duifang.name+"已阵亡,游戏结束") print(duifang.name+"已阵亡,游戏结束")
print("You Win") print("You Win")
exit()
def zhiliao(self):
if self.hp<250:
self.hp+=40
else:
print("血量已满,加血无效!")
while True:
yase = Hero("垭瑟") yase = Hero("垭瑟")
houyi= Hero("后羿") houyi= Hero("后羿")
\ No newline at end of file
yase.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