Commit 3ef94634 by BellCodeEditor

save project

parent dfb5d1b6
Showing with 53 additions and 0 deletions
# 英雄角色类
import time
import random
class Hero(object):
def __init__(self,name,hp,att):
self.level = 1
self.type = 'pc'
self.hp = hp
self.att = att
self.name = name
def combat(self,enemy): # 攻击
m = True
if self.type == 'pc':
m = self.hp > 60
else:
m = input(f'{self.name}1:攻击,2:治疗') == '1'
if m:
if random.randint(1,100) < 20:
enemy.hp -= self.att * 2
print(f'{self.name}对{enemy.name}发起进攻,造成了{self.att*2}点暴击伤害,')
else:
enemy.hp -= self.att
print(f'{self.name}对{enemy.name}发起进攻,造成了{self.att}点伤害,')
else:
self.hp += 20
print(f'{self.name}发起治疗,恢复了20点血,')
if enemy.hp <= 0:
print(f'{enemy.name}阵亡,游戏结束')
exit()
else:
print(f'{self.name}还剩{self.hp}点血')
print(f'{enemy.name}还剩{enemy.hp}点血')
yase = Hero("垭瑟",300,50)
houyi= Hero("后羿",250,60)
ch = input('请选择角色,1:垭瑟,2:后羿,3:观众')
if ch == '1':
yase.type='p'
elif ch == '2':
houyi.type='p'
huihe = 1
while True:
print(f'回合{huihe}')
print('-'*30)
yase.combat(houyi)
houyi.combat(yase)
print("-"*30)
huihe += 1
time.sleep(0.5)
\ 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