最近在自学python 正好组织游戏比赛能用到,就写了个随机抽选元素的代码,打个包就可以给别人用了
以下是源码 也有大佬指导我加上选兵种数量的功能,我搞了半天总是影响概率,就没搞。。
至少我现在这个概率是平均的→_→
注:我不是开发。。。大佬嘴下留情
# -*- coding: utf-8 -*-
import random
print(" **欢迎使用 谐星*随机抽取三兵种程序v1.1**")
print("开发(小白)兼测试兼文案 maybe#5383 本人可乐于为广大星际玩家提供此类形式的程序的技术支持" )
print(" **本规则在有裁判的情况下谐星效果更加**")
print("建议使用方法:")
print ()
print("1、由裁判运行程序并公示玩家随机到的单位,开始游戏")
print ()
print("2、由裁判运行程序 单独通知玩家可使用单位后开始游戏 增加戏剧性(需要正直的裁♂判)")
print ()
print("3、为避免抽取到的结果太过极端,建议抽取三次选取其中一次随机结果")
print ()
print("平衡性:虫族未抽到虫母时,允许其生产一只用来平衡")
while 1 <2:
print ()
print ()
print ("♞请输入你要验血统的种族 z p t ?")
zz = input ()
zerg = ['跳虫','爆虫','蟑螂','破坏者','刺蛇','潜伏者','腐化者','巢虫领主','宿主','王虫(升级空投)','虫后','飞蛇','雷兽','感染者','异龙']
protoss = ['狂热者','使徒','机械哨兵','追猎者','高阶圣堂武士','执政官','黑暗圣堂武士','折跃棱镜','不朽者','巨像','干扰者','凤凰','虚空辉光舰','先知','航母','风暴战舰']
protoss_1 = ['高阶圣堂武士','黑暗圣堂武士']
terran = ['陆战队员','劫掠者','收割者','幽灵','恶火(蝠)','攻城坦克','飓风','雷神','寡妇雷','医疗运输机','维京战机(机甲)','女妖','解放者','铁鸦','战列巡航舰']
aimeng = ['混合体巨兽','混合体掠夺者','混合体支配者','混合体天罚者','混合体毁灭者',]
if zz =="z":
zerg1 = random.choice(zerg)
zerg2 = random.choice(zerg)
while zerg2 == zerg1:
zerg2 = random.choice(zerg)
#zerg1 = "爆虫"
#zerg1 = "破坏者"
#zerg1 = "潜伏者"
#zerg1 = "巢虫领主"
if zerg1 == "爆虫":
zerg2 = "跳虫"
elif zerg1 == "破坏者":
zerg2 = "蟑螂"
elif zerg1 == "潜伏者":
zerg2 = "刺蛇"
elif zerg1 == "巢虫领主":
zerg2 = "腐化者"
zerg3 = random.choice(zerg)
#zerg2 = "爆虫"
#zerg2 = "破坏者"
#zerg2 = "潜伏者"
#zerg2 = "巢虫领主"
if zerg2 == "爆虫":
zerg3 = "跳虫"
elif zerg2 == "破坏者":
zerg3 = "蟑螂"
elif zerg2 == "潜伏者":
zerg3 = "刺蛇"
elif zerg2 == "巢虫领主":
zerg3 = "腐化者"
while zerg3 == zerg1 or zerg3 == "爆虫" or zerg3 == "破坏者"or zerg3 == "巢虫领主"or zerg3 == "潜伏者":
zerg3 = random.choice(zerg)
while zerg3 == zerg2 or zerg3 == "爆虫" or zerg3 == "破坏者"or zerg3 == "巢虫领主"or zerg3 == "潜伏者":
zerg3 = random.choice(zerg)
print ("你可使用的 无人权野怪 兵种如下:")
if zerg1 =='虫后' or zerg2 =='虫后' or zerg3 =='虫后':
print (zerg1 +"+"+ zerg2 +"+"+ zerg3+"+"+ "眼虫")
else :
print (zerg1 +"+"+ zerg2 +"+"+ zerg3+"+"+ "眼虫"+"+"+"一只虫后")
elif zz =="p":
protoss1 = random.choice(protoss)
protoss2 = random.choice(protoss)
#protoss1 = "执政官"
while protoss2 == protoss1:
protoss2 = random.choice(protoss)
if protoss1 == "执政官":
protoss2 = random.choice(protoss_1)
protoss3 = random.choice(protoss)
if protoss2 == "执政官":
protoss3 = random.choice(protoss_1)
#protoss3 = "执政官"
while protoss3 == protoss1 or protoss3 == "执政官":
protoss3 = random.choice(protoss)
while protoss3 == protoss2 or protoss3 == "执政官":
protoss3 = random.choice(protoss)
print ("你可使用的 imba P 的兵种如下:")
print (protoss1 +"+"+ protoss2 +"+"+ protoss3 +"+"+ "ob")
elif zz =="t":
terran1 = random.choice(terran)
terran2 = random.choice(terran)
terran3 = random.choice(terran)
while terran2 == terran1:
terran2 = random.choice(terran)
while terran3 == terran1:
terran3 = random.choice(terran)
while terran3 == terran2:
terran3 = random.choice(terran)
print ("你可使用的 imba T 兵种如下:")
print (terran1 +"+"+ terran2 +"+"+ terran3)
elif zz =="埃蒙":
print ("你抽到的兵种如下")
print ()
print (zerg + protoss + terran + aimeng)
print ("我群qq:542513722 ")
else:
print("你...你在说一遍你用什么族?")
print ()
print ("这。。这是个陷阱!弃船")
打包用的pyinstaller 这有教程
http://www.cnblogs.com/gopythoner/p/6337543.html