Commit 6e0b2753 by BellCodeEditor

auto save

parent 1908b6f2
import random
class Hero(object): class Hero(object):
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
...@@ -7,7 +9,9 @@ class Hero(object): ...@@ -7,7 +9,9 @@ class Hero(object):
self.max_hp = self.hp self.max_hp = self.hp
def cure(self): # 治疗 def cure(self): # 治疗
??? self.hp += 60
if self.hp > self.max_hp:
self.hp=self.max_hp
print(self.name+"使用了治疗,血量增加:", 60,",目前的血量为:",self.hp) print(self.name+"使用了治疗,血量增加:", 60,",目前的血量为:",self.hp)
def combat(self, enemy): # 普通攻击 def combat(self, enemy): # 普通攻击
...@@ -33,10 +37,36 @@ class Player(Hero): ...@@ -33,10 +37,36 @@ 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)
def cure(self): # 治疗
blood=random.randint(30,50)
self.hp += blood
if self.hp > self.max_hp:
self.hp=self.max_hp
print(self.name+"使用了治疗,血量增加:", blood,",目前的血量为:",self.hp)
houyi = Player("射手", "后羿") houyi = Player("射手", "后羿")
yase = Hero("垭瑟") yase = Hero("垭瑟")
houyi.combat(yase) print('-'*30)
yase.combat(houyi) print(' 战斗开始')
houyi.cure() while True:
yase.cure() #玩家
\ No newline at end of file print('-'*30)
a=input("请释放技能(1攻击/2治疗)>>>")
if a=="q":
print("游戏结束")
break#跳出全部循环
elif a=="1":
houyi.combat(yase)
elif a=="2":
houyi.cure()
else:
print("请释放技能(1攻击/2治疗)>>>")
continue#跳出本次循环
#电脑
num=random.randint(1,3)
if num==1:
yase.combat(houyi)
elif num==2:
yase.cure()
else:
pass
#冒泡排序----从大到小
list=[6,2,4,8,10,1,9,3,7,0,5]
#列表长度
n=len(list)
#比较轮数
for i in range(n-1):
#每一轮相邻元素比较次数
for j in range(n-1):
if list[j]<list[j+1]:
list[j],list[j+1]=list[j+1],list[j]
print(list)
a=int(input("请输入>>>"))
#递归
def func(n):
#边界条件
if n==1:
return 1
else:
#递归条件
s=n*func(n-1)
return s
print(func(a))
\ No newline at end of file
#计算前n项奇数的和
def s(n):
if n%2==0:
n=n-1
#边界条件 if------else
if n==1:
return 1
else:
#递归条件
sum=n+s(n-2)
return sum
print(s(99))
\ No newline at end of file
#快速排序
array=[2,3,5,7,1,4,6,15,5,2,7,9,10,15,9,17,12]
def quick_sort(list):
if len(list)>=2:
#分界值
mid=len(list)//2
left=[]
right=[]
middle=list[mid]
list.remove(list[mid])#删除分界值
for i in list:
if i<middle:
left.append(i)
else:
right.append(i)
return quick_sort(left)+[middle]+quick_sort(right)
else:
return list
print(quick_sort(array))
\ No newline at end of file
# str1="中"
# str2="国"
# print(str1+str2)
left=[1,2,3]
right=[4,5,6]
print(left+right)
\ 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