Commit d9cfa316 by BellCodeEditor

auto save

parent f19096ae
Showing with 75 additions and 0 deletions
import time
class Hero(object):
def __init__(self, name):
self.name = name
self.level = 1
self.hp = 250
self.attack = 40
self.max_hp = self.hp
self.gp = 0
self.max_gp = self.level * 100
def upgrade(self):
self.level += 1
self.max_hp *= 1.2
self.attack *= 1.2
self.hp = self.max_hp
def cure(self): # 治疗
if self.hp + 60 > self.max_hp:
self.hp = self.max_hp
else:
self.hp += 60
print(self.name+"使用了治疗,血量增加:", 60,",目前的血量为:",self.hp)
def combat(self, enemy): # 普通攻击
info1 = self.name+"对"+enemy.name+"发起进攻,"
info2 = "造成"+str(self.attack)+"点伤害,"
enemy.hp -= self.attack
self.gp += 15
if self.gp >= self.max_gp:
self.upgrade()
info5 = self.name + '升级' + '\n' + '等级为' + self.level + '\n' + '血量为' + self.hp + '\n' + '攻击力为:' + self.attack
else:
info5 = ''
if enemy.hp > 0:
info3 = enemy.name+"还剩下"+str(enemy.hp)+"血量"
info4 = '您的经验增加了' + '15'
info = info1+info2+info4+info5
print(info)
else:
info3 = enemy.name+"阵亡,游戏结束"
info4 = '您的经验增加了' + '30'
info = info1+info2+info3+info4+info5
self.gp += 15
print(info)
exit()
class Player(Hero):
def __init__(self,hero_type,name):
super().__init__(name)
self.hp = 200
self.attack = 50
self.max_hp = self.hp
self.hero_type = hero_type
print("角色"+self.name+"创建成功,英雄类型为:", self.hero_type)
print("当前等级、血量、攻击力分别为:",self.level,self.hp,self.attack)
houyi = Player("射手", "后羿")
yase = Hero("垭瑟")
print('-' * 30 + '\n 游戏开始')
while True:
time.sleep(0.5)
print('-'*30)
time.sleep(0.5)
c = input('请选择释放英雄技能(1攻击/2治疗):')
if c == '1' or c == '攻击':
time.sleep(0.5)
houyi.combat(yase)
elif c == '2' or c == '治疗':
time.sleep(0.5)
houyi.cure()
else:
time.sleep(0.5)
print('输入错误!')
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