Commit e1a9060e by BellCodeEditor

save project

parent 1908b6f2
Showing with 43 additions and 10 deletions
import random
class Hero(object):
def __init__(self, name):
self.name = name
......@@ -5,24 +6,34 @@ class Hero(object):
self.hp = 250
self.attack = 40
self.max_hp = self.hp
self.shield=0
def cure(self): # 治疗
???
print(self.name+"使用了治疗,血量增加:", 60,",目前的血量为:",self.hp)
self.hp=self.hp+30
if self.hp>self.max_hp:
self.hp=self.max_hp
print(self.name+"使用了治疗,血量增加:", 30,",目前的血量为:",self.hp)
def combat(self, enemy): # 普通攻击
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害,"
enemy.hp -= self.attack
if enemy.hp > 0:
if enemy.shield>self.attack:
enemy.shield-=self.attack
info3 =enemy.name+"还剩下"+str(enemy.shield)+"护盾"
else:
enemy.hp = enemy.hp-(self.attack-enemy.shield)
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
if enemy.hp > 0:
info = info1+info2+info3
print(info)
print(info)
else:
info3 = enemy.name+"阵亡,游戏结束"
info = info1+info2+info3
print(info)
exit()
def beshield(self): #护盾
self.shield=self.shield+50
print(self.name+"使用了护盾发生器,增加了"+str(50)+"护盾")
class Player(Hero):
def __init__(self,hero_type,name):
......@@ -36,7 +47,30 @@ class Player(Hero):
houyi = Player("射手", "后羿")
yase = Hero("垭瑟")
houyi.combat(yase)
yase.combat(houyi)
houyi.cure()
yase.cure()
\ No newline at end of file
print('-'*30)
print(' 游戏开始')
print('-'*30)
while True:
choice = input("请选择释放英雄技能(1攻击/2治疗/3护盾)")
if choice=="q":
print("游戏结束")
break
elif choice=="1":
houyi.combat(yase)
elif choice=="2":
houyi.cure()
elif choice=="3":
houyi.beshield()
else:
print("请重新输入1或2")
continue
choice=random.randint(1,3)
if choice==1:
yase.combat(houyi)
elif choice==2:
yase.cure()
else:
yase.beshield()
print('-'*30)
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