Commit ebdeccfe by BellCodeEditor

save project

parent 0cf4adde
Showing with 16 additions and 10 deletions
...@@ -7,6 +7,12 @@ class Hero(object): ...@@ -7,6 +7,12 @@ class Hero(object):
self.attack = 40 self.attack = 40
self.max_hp = self.hp self.max_hp = self.hp
def cure(self):
self.hp+=60
if self.hp>self.max_hp:
self.hp=self.max_hp
print(self.name+"使用了治疗,血量增加:",60,",目前的血量为:",self.hp)
def combat(self, enemy): # 普通攻击 def combat(self, enemy): # 普通攻击
...@@ -35,12 +41,12 @@ class Player(Hero): ...@@ -35,12 +41,12 @@ class Player(Hero):
print("当前等级、血量、攻击力分别为:",self.level,self.hp,self.attack) print("当前等级、血量、攻击力分别为:",self.level,self.hp,self.attack)
print('-'*30) print('-'*30)
print(' 战斗开始') print(' 战斗开始')
def cure(self): def cure(self):
c=random.randint(35,50) c=random.randint(35,50)
self.hp+=c self.hp+=c
if self.hp>self.max_hp: if self.hp>self.max_hp:
self.hp=self.max_hp self.hp=self.max_hp
print(self.name+"使用了治疗,血量增加:",str(c),",目前的血量为:",self.hp) print(self.name+"使用了治疗,血量增加:",str(c),",目前的血量为:",self.hp)
houyi = Player("射手", "后羿") houyi = Player("射手", "后羿")
yase = Hero("垭瑟") yase = Hero("垭瑟")
...@@ -50,7 +56,7 @@ while True: ...@@ -50,7 +56,7 @@ while True:
if a == "1": if a == "1":
houyi.combat(yase) houyi.combat(yase)
elif a == "2": elif a == "2":
cure(houyi) houyi.cure()
elif a == "q": elif a == "q":
print("游戏退出") print("游戏退出")
break break
...@@ -59,10 +65,10 @@ while True: ...@@ -59,10 +65,10 @@ while True:
continue continue
num=random.randint(1,3) num=random.randint(1,3)
if num == "1" or "2": if num == 1 or num==2:
yase.combat(houyi) yase.combat(houyi)
elif num == "3": elif num == 3:
cure(yase) yase.cure()
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