Commit 0e6abb81 by BellCodeEditor

auto save

parent e64e6922
Showing with 38 additions and 10 deletions
import random # 导入random模块
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.max_hp = self.hp # 设置最大血量值
def cure(self): # 治疗
???
print(self.name+"使用了治疗,血量增加:", 60,",目前的血量为:",self.hp)
def cure(self): # def定义治疗术
self.hp=self.hp + 60 # 血量增加60
if self.hp > self.max_hp: # if条件判断,如果治疗后的血量大于最大血量值
self.hp = self.max_hp # 则血量设置为最大血量值
print(self.name+"使用了治疗,血量增加:", 60,",目前的血量为:",self.hp) # 打印治疗信息
def combat(self, enemy): # 普通攻击
info1 = self.name+"对"+enemy.name+"发起进攻,"
......@@ -29,14 +33,38 @@ class Player(Hero):
super().__init__(name)
self.hp = 200
self.attack = 50
self.max_hp = self.hp
self.max_hp = self.hp # 将初始化血量值赋值给它
self.hero_type = hero_type
print("角色"+self.name+"创建成功,英雄类型为:", self.hero_type)
print("当前等级、血量、攻击力分别为:",self.level,self.hp,self.attack)
def cure(self): # def定义治疗术
blood = random.randint(30,50) # 生成30~50之间随机数赋值给变量blood
self.hp=self.hp + blood # 血量增加blood
if self.hp > self.max_hp: # if条件判断,如果治疗后的血量大于最大血量值
self.hp = self.max_hp # 则血量设置为最大血量值
print(self.name+"使用了治疗,血量增加:", blood,",目前的血量为:",self.hp) # 打印治疗信息
houyi = Player("射手", "后羿")
yase = Hero("垭瑟")
houyi.combat(yase)
yase.combat(houyi)
houyi.cure()
yase.cure()
\ No newline at end of file
print('-' * 30) # 打印-*30作为分隔符
print(' 战斗开始') # 打印出战斗开始
while True: # 设置循环
print("-"*30) # 打印-*30作为分隔符
choice = input("请选择释放英雄技能(1攻击/2治疗):") # 选择=输入(内容)
if choice == "q": # if判断选择q
print("游戏结束") # 打印出游戏结束
break # 结束程序
elif choice == "1": # if判断选择1
houyi.combat(yase) # 后羿攻击亚瑟
elif choice == "2": # if判断选择2
houyi.cure() # 后羿治疗
else: # 否则
print("请重新输入1或者2") # 打印出,请重新输入1或者2
continue # 进入下一轮循环
num = random.randint(1,3) # 生成1~3随机数赋值给num
if num == 1: # if判断num的值=1
yase.cure() # 亚瑟治疗
else: # 否则
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