Commit fd761198 by BellCodeEditor

save project

parent c8a03acb
Showing with 23 additions and 24 deletions
import random import random
lantiao = 10 lantiao = 0
hit = [7000,8000,9000,10000] hit = [7000,8000,9000,10000]
cint = random.choice(hit) cint = random.choice(hit)
class Hero(object): class Hero(object):
...@@ -11,17 +11,18 @@ class Hero(object): ...@@ -11,17 +11,18 @@ class Hero(object):
self.max_hp = self.hp self.max_hp = self.hp
def cure(self): # 治疗 def cure(self): # 治疗
global lantiao
self.hp+=cint self.hp+=cint
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+"服用了一枚治疗丹,血量增加:", cint,",目前的血量为:",self.hp) print(self.name+"服用了一枚治疗丹,血量增加:", cint,",目前的血量为:",self.hp)
lantiao += 1 lantiao = lantiao+1
def combat(self, enemy): # 普通攻击 def combat(self, enemy): # 普通攻击
global lantiao
info1 = self.name+"对"+enemy.name+"扔出一把飞刀," info1 = self.name+"对"+enemy.name+"扔出一把飞刀,"
info2 = "造成"+str(self.attack)+"点伤害," info2 = "造成"+str(self.attack)+"点伤害,"
enemy.hp -= self.attack enemy.hp -= self.attack
lantiao += 1 lantiao = lantiao+1
if lantiao > 10: if lantiao > 10:
lantiao = 10 lantiao = 10
if enemy.hp > 0: if enemy.hp > 0:
...@@ -39,26 +40,28 @@ class Hero(object): ...@@ -39,26 +40,28 @@ class Hero(object):
exit() exit()
def qiang(self,enemy): def qiang(self,enemy):
self.huai = self.attack+5000 global lantiao
infu1 = self.name+"对"+enemy.name+"发起攻击," if lantiao >= 8:
infu2 = "造成"+str(self.huai)+"点伤害," lantiao = lantiao-8
enemy.hp -= self.huai self.huai = self.attack+5000
lantiao += 1 infu1 = self.name+"对"+enemy.name+"发起攻击,"
if lantiao > 10: infu2 = "造成"+str(self.huai)+"点伤害,"
lantiao = 10 enemy.hp -= self.huai
if enemy.hp > 0: if enemy.hp > 0:
infu3 = enemy.name+"还剩下"+str(enemy.hp)+"血量" infu3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
infu = infu1+infu2+infu3 infu = infu1+infu2+infu3
print(infu) print(infu)
else: else:
infu3 = enemy.name+"阵亡,游戏结束" infu3 = enemy.name+"阵亡,游戏结束"
infu = infu1+infu2+infu3 infu = infu1+infu2+infu3
print(infu) print(infu)
if enemy.hp <= 0: if enemy.hp <= 0:
print("胜利") print("胜利")
if self.hp <= 0: if self.hp <= 0:
print("失败") print("失败")
exit() exit()
if lantiao < 8:
print("蓝条不够,不能使用")
class Player(Hero): class Player(Hero):
def __init__(self,hero_type,name): def __init__(self,hero_type,name):
...@@ -88,11 +91,7 @@ while True: ...@@ -88,11 +91,7 @@ while True:
elif int(a)==2: elif int(a)==2:
houyi.cure() houyi.cure()
elif int(a)==3: elif int(a)==3:
if lantiao >= 8: houyi.qiang(yase)
lantiao -= 8
houyi.qiang(yase)
else:
print("蓝条不够,不可使用")
elif a=="q": elif a=="q":
print('游戏结束') print('游戏结束')
break break
......
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