Commit bd837bca by BellCodeEditor

save project

parent 7375d9ee
Showing with 7 additions and 43 deletions
import random
class Hero(object): class Hero(object):
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
...@@ -8,13 +7,12 @@ class Hero(object): ...@@ -8,13 +7,12 @@ class Hero(object):
self.max_hp = self.hp self.max_hp = self.hp
def cure(self): # 治疗 def cure(self): # 治疗
add=random.randint(30,60) self.hp+=60
self.hp+=add
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(add),",目前的血量为:",self.hp) print(self.name+"使用了治疗,血量增加:", 60,",目前的血量为:",self.hp)
def combat(self, enemy): # 普通攻击 def combat(self, enemy): # 普通攻击
info1 = self.name+"对"+enemy.name+"发起进攻," info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害," info2 = "造成"+str(self.attack)+"点伤害,"
...@@ -38,44 +36,10 @@ class Player(Hero): ...@@ -38,44 +36,10 @@ class Player(Hero):
self.hero_type = hero_type self.hero_type = hero_type
print("角色"+self.name+"创建成功,英雄类型为:", self.hero_type) print("角色"+self.name+"创建成功,英雄类型为:", self.hero_type)
print("当前等级、血量、攻击力分别为:",self.level,self.hp,self.attack) print("当前等级、血量、攻击力分别为:",self.level,self.hp,self.attack)
print('-'*20)
print('战斗开始')
print('-'*20)
houyi = Player("射手", "后羿") houyi = Player("射手", "后羿")
yase = Hero("垭瑟") yase = Hero("垭瑟")
houyi.combat(yase)
yase.combat(houyi)
while True: houyi.cure()
if houyi.hp>0 and yase.hp>0: yase.cure()
choice=input('请选择释放英雄技能(1攻击/2治疗),按q退出') \ No newline at end of file
print('*'*20)
if choice=='q':
print('游戏结束')
exit()
elif choice=='1':
houyi.combat(yase)
y=random.randint(1,2)
if y==1:
yase.combat(houyi)
else:
yase.cure()
elif choice=='2':
houyi.cure()
y=random.randint(1,3)
if y==1:
yase.combat(houyi)
else:
yase.cure()
else:
print('请重新输入')
print('*'*20)
if houyi.hp<=0:
print('后羿阵亡,游戏结束')
break
if yase.hp<=0:
print('垭瑟阵亡,游戏结束')
break
\ 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