Python LOL云顶之翼小游戏@[QZ]

Py代码如下

// An highlighted block
'''
QZ
'''
import random
flag=True #True A回合;False B回合
All_hero="盖伦 剑圣 诺手 提莫 派克"#英雄列表  All_hero="盖伦剑圣诺手提莫派克盖伦盖伦盖伦"  str1 = list(set(All_hero))

#A属性
A_hero=""#A-初始英雄列表为空
A_max=0 #A重复英雄的数量
A_gold=5 #A初始金币数量
#B属性
B_hero=""#B-初始英雄列表为空
B_max=0 #B重复英雄的数量
B_gold=5 #B初始金币数量

#计算每个玩家英雄列表中重复英雄的数量
def maxhero(herolist) :
	i=0
	a=[]
	while(i<len(herolist)/2) :
		a.append(herolist.count(herolist[2*i:2*i+2],0,len(herolist)))#计算每种英雄在列表中重复的次数
		i=i+1
	#排序
	number=a[0]
	for m in range(1,len(a)):
		if a[m]>number :
			number=a[m]
		else :
			continue
	return number

#计算并显示英雄星级
def hero_star(herolist) :# 二维数组定义 arr = [[0]*2 for _ in range(5)]
	#去除英雄列表重复英雄,获得各个玩家英雄种类
	flag=0
	remove_repeated_hero = herolist[0:2]
	for i in range(1,int(len(herolist)/2)):
		for j in range(0,i) :
			if remove_repeated_hero[2*j:2*j+2]==herolist[2*i:2*i+2] :
				flag=1
				break
			else :
				continue
		if flag==0 :
			remove_repeated_hero=remove_repeated_hero+herolist[2*i:2*i+2]
		else :
			flag=0

	hero_kind_num = [[0]*2 for _ in range(len(remove_repeated_hero))]#定义二维数组,第一列存储英雄名字;第二列存储英雄数量
	for j in range(0,len(remove_repeated_hero)) :
		hero_kind_num[j][0]=remove_repeated_hero[2*j:2*j+2]#将英雄名称赋值到二维数组第一列
		hero_kind_num[j][1]=herolist.count(remove_repeated_hero[2*j:2*j+2],0,len(herolist))#将英雄数量赋值到二维数组第二列
	print("英雄名称  一星  二星   三星")
	for m in range(0,int(len(remove_repeated_hero)/2)):
			print(" ",hero_kind_num[m][0],"\t  ",(hero_kind_num[m][1]-(hero_kind_num[m][1]//9)*9)%3,"\t",(hero_kind_num[m][1]-(hero_kind_num[m][1]//9)*9)//3,"\t",hero_kind_num[m][1]//9)

#计算玩家金钱
def player_gold(gold):
	if gold//10>=1 :
		gold=(gold//10)*1+gold+5 #本金+利息+每局盈利
	else :
		gold=gold+5 #本金+每局盈利
	return gold

#初始选英雄
#A
print("\t\tA玩家选英雄\n1盖伦2剑圣3诺手4提莫5派克")#英雄编号
A_num=input("玩家A请输入英雄编号:")
A_hero=A_hero+All_hero[3*(int(A_num)-1):3*(int(A_num)-1)+2]
#初始选英雄
#B
print("\t\tB玩家选英雄\n1盖伦2剑圣3诺手4提莫5派克")#英雄编号
B_num=input("玩家B请输入英雄编号:")
B_hero=B_hero+All_hero[3*(int(B_num)-1):3*(int(B_num)-1)+2]

Round=1 #回合次数
while (A_max<9 and B_max<9) :
	#指令门票5gold,拿英雄不扣钱
	#刷新系统进入不要金,刷新一次扣2金,每个英雄1金
	if flag :#A抽牌回合
		flag=False
		A_order=input("\t\tA玩家\n请输入指令:'1'进入抽牌;'2'进入刷新抽牌") #A玩家抽牌指令‘1’
		if (A_order=="1"and A_gold>=5):#指令拿英雄
			A_gold=A_gold-5 #一进入就扣钱
			A_rd=random.randint(1,5)
			print("A玩家金钱:%d"%A_gold)
			print("A玩家抽到英雄为:",All_hero[3*(A_rd-1):3*(A_rd-1)+2])
			print("是否将\"",All_hero[3*(A_rd-1):3*(A_rd-1)+2],"\"添加到英雄列表中?")
			A_choice=input("Y 添加 N 丢弃\n")#A 抽取到的英雄选择要或是不要
			if(A_choice=='Y'):
				A_hero=A_hero+All_hero[3*(A_rd-1):3*(A_rd-1)+2]
				A_max=maxhero(A_hero)
				print("A玩家当前英雄列表: %s"%A_hero)
				print("A玩家当前英雄列表相同英雄最多数量为:%d"%A_max)
				hero_star(A_hero)
			else :
				print("A玩家放弃抽取到英雄!")
				A_max=maxhero(A_hero)
				print("A玩家当前英雄列表相同英雄最多数量为:%d"%A_max)
				hero_star(A_hero)
				#A抽到不要此英雄
			print("A玩家本轮剩余金钱:%d"%A_gold)
			print("\n")
			A_gold=player_gold(A_gold)#回合金钱计算
		else :#刷新拿英雄
			print("指令系统进入失败,进入刷新英雄系统!")
			print("A玩家金钱:%d"%A_gold)
			#随机刷出3英雄 c
			A_hero1_num=random.randint(1,5)
			A_hero1=All_hero[3*(A_hero1_num-1):3*(A_hero1_num-1)+2]
			A_hero2_num=random.randint(1,5)
			A_hero2=All_hero[3*(A_hero2_num-1):3*(A_hero2_num-1)+2]
			A_hero3_num=random.randint(1,5)
			A_hero3=All_hero[3*(A_hero3_num-1):3*(A_hero3_num-1)+2]
			print("本轮随机英雄:1、%s,2、%s,3、%s"%(A_hero1,A_hero2,A_hero3))
			if(A_gold>=1) :
				A_refresh_hero=input("请选择需要购买的英雄编号:")
				A_refresh_num=input("请输入购买英雄的数量:")
				print("最多可以购买%d个英雄!(超出购买范围将购买失败!)"%A_gold)
				A_gold=A_gold-int(A_refresh_num)
				if A_refresh_hero=='1' :
					A_hero=A_hero+A_hero1*int(A_refresh_num)
				elif A_refresh_hero=='2' :
					A_hero=A_hero+A_hero2*int(A_refresh_num)
				elif A_refresh_hero=='3' :
					A_hero=A_hero+A_hero3*int(A_refresh_num)
			else :
				print("金币不足无法购买!")
			A_max=maxhero(A_hero)
			print("A玩家当前英雄列表: %s"%A_hero)
			print("A玩家当前英雄列表相同英雄最多数量为:%d"%A_max)
			hero_star(A_hero)
			print("A玩家本轮剩余金钱:%d"%A_gold)
			print("\n")
			A_gold=player_gold(A_gold)#回合金钱计算
	else :#B抽牌回合		
		flag=True
		B_order=input("\t\tB玩家\n请输入指令:'2'进入抽牌;'1'进入刷新抽牌") #B玩家抽牌指令‘2’
		if B_order=="2":
			B_gold=B_gold-5#一进入就扣钱
			B_rd=random.randint(1,5)
			print("B玩家金钱:%d"%B_gold)
			print("B玩家抽到英雄为:",All_hero[3*(B_rd-1):3*(B_rd-1)+2])
			print("是否将\"",All_hero[3*(B_rd-1):3*(B_rd-1)+2],"\"添加到英雄列表中?")
			B_choice=input("Y 添加 N 丢弃\n")#B 抽取到的英雄选择要或是不要
			if(B_choice=='Y'):
				B_hero=B_hero+All_hero[3*(B_rd-1):3*(B_rd-1)+2]
				B_max=maxhero(B_hero)
				print("B玩家当前英雄列表: %s"%B_hero)
				print("B玩家当前英雄列表相同英雄最多数量为:%d"%B_max)
				hero_star(B_hero)
				print("******************第%d回合结束*****************"%Round)
				Round=Round+1
			else :
				print("B玩家放弃抽取到英雄!")
				B_max=maxhero(B_hero)
				print("B玩家当前英雄列表相同英雄最多数量为:%d"%B_max)
				hero_star(B_hero)
				print("******************第%d回合结束*****************"%Round)
				Round=Round+1
				#B抽到不要此英雄
			print("B玩家本轮剩余金钱:%d"%B_gold)
			print("\n")
			B_gold=player_gold(B_gold)#回合金钱计算
		else :#刷新拿英雄
			print("指令系统进入失败,进入刷新英雄系统!")
			print("B玩家金钱:%d"%B_gold)
			B_hero1_num=random.randint(1,5)
			B_hero1=All_hero[3*(B_hero1_num-1):3*(B_hero1_num-1)+2]
			B_hero2_num=random.randint(1,5)
			B_hero2=All_hero[3*(B_hero2_num-1):3*(B_hero2_num-1)+2]
			B_hero3_num=random.randint(1,5)
			B_hero3=All_hero[3*(B_hero3_num-1):3*(B_hero3_num-1)+2]
			print("本轮随机英雄:1、%s,2、%s,3、%s"%(B_hero1,B_hero2,B_hero3))
			if(B_gold>=1):
				B_refresh_hero=input("请选择需要购买的英雄编号:")
				B_refresh_num=input("请输入购买英雄的数量:")
				print("最多可以购买%d个英雄!(超出购买范围将购买失败!)"%B_gold)
				B_gold=B_gold-int(B_refresh_num)
				if B_refresh_hero=='1' :
					B_hero=B_hero+B_hero1*int(B_refresh_num)
				elif B_refresh_hero=='2' :
					B_hero=B_hero+B_hero2*int(B_refresh_num)
				elif B_refresh_hero=='3' :
					B_hero=B_hero+B_hero3*int(B_refresh_num)
			else:
				print("金币不足无法购买!")
			A_max=maxhero(A_hero)
			print("B玩家当前英雄列表: %s"%B_hero)
			print("B玩家当前英雄列表相同英雄最多数量为:%d"%B_max)
			hero_star(B_hero)
			print("******************第%d回合结束*****************"%Round)
			Round=Round+1
			print("B玩家本轮剩余金钱:%d"%B_gold)
			print("\n")
			B_gold=player_gold(B_gold)#回合金钱计算

if A_max==9 :
	print("A获胜!")
elif B_max==9:
	print("B获胜!")