Commit 70d7949f by BellCodeEditor

save project

parent 7ff9be45
Showing with 15 additions and 9 deletions
...@@ -5,6 +5,7 @@ class Hero: # 英雄类 ...@@ -5,6 +5,7 @@ class Hero: # 英雄类
self.name = name self.name = name
self.level = 1 self.level = 1
self.hp = '出错了!"hp"未设置' self.hp = '出错了!"hp"未设置'
self.hp_max = self.hp
self.attack = '出错了!"attack"未设置' self.attack = '出错了!"attack"未设置'
self.max_hp = self.hp self.max_hp = self.hp
...@@ -23,14 +24,19 @@ class Hero: # 英雄类 ...@@ -23,14 +24,19 @@ class Hero: # 英雄类
print(info) print(info)
exit() exit()
def ziliao(self, ememy): def cure(self):
ememy.hp = ememy.hp + 10 self.hp = self.hp + 10
print(str(ememy.name),'回血成功!血量加10点,目前血量:',str(ememy.hp)) if self.hp > self.hp_max:
self.hp = 250
print(str(self.name),'血量已达到最大限制!')
else:
print(str(self.name),'回血成功!血量加10点,目前血量:',str(self.hp))
class Player(Hero): # 玩家英雄 class Player(Hero): # 玩家英雄
def __init__(self,name,hp,attack): def __init__(self,name,hp,attack):
super().__init__(name) super().__init__(name)
self.hp = hp self.hp = hp
self.hp_max = self.hp
self.attack = attack self.attack = attack
print(str(self.name)+'创建成功!血量:',str(self.hp),',攻击力:',str(self.attack)) print(str(self.name)+'创建成功!血量:',str(self.hp),',攻击力:',str(self.attack))
...@@ -42,10 +48,10 @@ while True: ...@@ -42,10 +48,10 @@ while True:
user_input = str(input('请选择英雄技能(1:攻击,2:回血)')) user_input = str(input('请选择英雄技能(1:攻击,2:回血)'))
if user_input == "1": if user_input == "1":
player1.combat(player2) player1.combat(player2)
pl_hp_a = player2.hp if player2.hp > 50:
if pl_hp_a < 20:
player1.ziliao(player2)
else:
player2.combat(player1) player2.combat(player1)
else:
player2.cure()
if user_input == "2": if user_input == "2":
player2.ziliao(player1) player2.cure()
\ No newline at end of file player1.cure()
\ 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