Commit 02bf88b3 by BellCodeEditor

auto save

parent 9a581ef4
Showing with 50 additions and 12 deletions
# 英雄角色类 import time
class Hero(object): import random
def __init__(self, name):
self.level = 1 class Hero():
self.hp = 250 def __init__(self, name, hp, att, heal=20):
self.attack = 40 self.lv = 1
self.name = name self.name = name
self.hp = hp
self.att = att
self.heal = heal
# def upgrade(self):
# self.lv += 1
# self.hp += 50
# self.att += 4
def combat(self, enemy):
if self.hp > 40:
if random.randint(1, 100) <= 33:
# 暴击
enemy.hp -= self.att * 2
print(f'{self.name}对{enemy.name}发起了强攻,造成{self.att*2}点暴击伤害,', end="")
else:
# 普通攻击
enemy.hp -= self.att
print(f'{self.name}对{enemy.name}发起了进攻,造成{self.att}点伤害,', end="")
else:
self.hp += 20
print(f'{self.name}对自己使用了治疗,恢复20点生命', end="")
if enemy.hp < 0:
print(f'{enemy.name}阵亡,游戏结束。')
exit()
else:
print(f'{enemy.name}还剩下{enemy.hp}点血量。')
yase = Hero('yase', 300, 25)
houyi = Hero('houyi', 260, 30)
while True:
houyi.combat(yase)
yase.combat(houyi)
print('=============================================================')
def combat(): # 攻击 time.sleep(2)
???
yase = Hero("垭瑟") # print(f'级别:{yase.lv} 血量:{yase.hp} 攻击力:{yase.att}')
houyi= Hero("后羿") \ No newline at end of file
yase.combat(houyi)
\ 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