三國志戰略版抽卡模擬器,python tkinter庫,計算你的歐非程度


#!/usr/bin/python3
# -*- coding: utf-8 -*- 
import random
from tkinter import *
from tkinter import messagebox
from PIL import Image

cheng=["劉備","關羽","張飛","曹操","孫權","孫策","曹植","王平","龐德","祝融夫人","鄧艾",
        "典韋","賈詡","司馬懿","張遼","龐統","馬超","諸葛亮","孫尚香","張肱","張昭","陸遜",
        "袁紹","袁術","孟獲","於吉","董卓","呂布","陳群","許褚","張郃","郝昭","曹仁",
        "甄姬","程昱","荀彧","荀攸","徐晃","夏侯惇","鍾會","嚴顏","關銀屏","馬雲祿","陳到",
        "姜維","黃忠","趙雲","凌統","魯肅","甘寧","周泰","呂蒙","太史慈","孫堅","陸抗",
        "周瑜","田豐","呂玲綺","兀突骨","公孫瓚","張角","曹純","於禁","樂進","鄧艾","夏侯淵",
        "郭嘉","蔣琬","徐庶","黃蓋","程普","孫策","高嵐","木鹿大王","李儒","高順","馬騰",
        "文丑","華雄","顏良","華佗","左慈","曹丕","張姬","黃月英","法正","大喬","貂蟬",
        "陳宮","司馬徽","張春華","小喬","蔡文姬"]

def card():
    global num,rac_orange
    rac_puple=0.3
    rac_blue=1-rac_orange-rac_puple
    if num==30:
        y=random.randint(0,len(cheng)-1)
        print("出橙: {}".format(cheng[y]))
        num=0
        return cheng[y]
    x=random.randint(0,1000)
    if x<=rac_orange*1000:
        y=random.randint(0,len(cheng)-1)
        print("出橙: {}".format(cheng[y]))
        num=0
        return cheng[y]
    elif x<=rac_puple*1000:
        print("出紫")
        num+=1
        return 1
    else:
        print("出藍")
        num+=1
        return 0

def tongji():
    global num,n1,n2,n3,chucheng
    content=""
    for item in chucheng:content=content+item+","
    content=content[:-1]
    label_num_1 = Label(root,text="共計出橙{}次".format(n1)).place(x=30,y=190)
    label_num_2 = Label(root,text="共計出紫{}次".format(n2)).place(x=30,y=210)
    label_num_3 = Label(root,text="共計出藍{}次".format(n3)).place(x=30,y=230)
    label_num_4 = Label(root,text="還有{}次保底".format(30-num)).place(x=30,y=260)
    label_num_5 = Label(root,text="當前出橙:{}".format(content),wraplength=700).place(x=30,y=290)


def on_click_1():
    global num,n1,n2,n3,chucheng
    n=1
    for i in range(n):
        z=card()
        if z==1:n2+=1
        elif z==0:n3+=1
        else:
            n1+=1
            chucheng.append(z)
    tongji()

def on_click_2():
    global num,n1,n2,n3,chucheng
    n=10
    for i in range(n):
        z=card()
        if z==1:n2+=1
        elif z==0:n3+=1
        else:
            n1+=1
            chucheng.append(z)
    tongji()

def on_click_3():
    global num,n1,n2,n3,chucheng
    n=100
    for i in range(n):
        z=card()
        if z==1:n2+=1
        elif z==0:n3+=1
        else:
            n1+=1
            chucheng.append(z)
    tongji()

def do_job1():
    global var
    var=StringVar()
    r1 = Radiobutton(root, text='A:', variable=var, value='1').place(x=30,y=80)#單選框
    label1 = Label(root,text="3%").place(x=80,y=80)
    r2 = Radiobutton(root, text='B:', variable=var, value='2').place(x=30,y=100)
    label2 = Label(root,text="5.6%").place(x=80,y=100)
    r3 = Radiobutton(root, text='C:', variable=var, value='3').place(x=30,y=120)
    label3 = Label(root,text="10%").place(x=80,y=120)
    r4 = Radiobutton(root, text='D:', variable=var, value='4').place(x=30,y=140)
    label4 = Label(root,text="20%").place(x=80,y=140)
    button = Button(root,text='確定',command=do_job4)
    button.place(x=30,y=160)

def do_job2():
    global num
    num=0
    messagebox.showinfo(title='提示',message='保底已重置')

def do_job4():
    global var,rac_orange
    if var.get()=='1':rac_orange=0.03
    elif var.get()=='2':rac_orange=0.056
    elif var.get()=='3':rac_orange=0.1
    elif var.get()=='4':rac_orange=0.2
    else:rac_orange=0.03
    messagebox.showinfo(title='提示',message='當前出橙概率:'+str(rac_orange))

def do_job3():
    global n1,n2,n3,chucheng
    space="    "*1000
    n1=n2=n3=0
    chucheng=[]
    label_num_6 = Label(root,text=space).place(x=30,y=190)
    label_num_7 = Label(root,text=space).place(x=30,y=210)
    label_num_8 = Label(root,text=space).place(x=30,y=230)
    label_num_9 = Label(root,text=space,wraplength=700).place(x=30,y=290)
    label_num_4 = Label(root,text="還有{}次保底".format(30)).place(x=30,y=260)
    tongji()
    messagebox.showinfo(title='提示',message='計數已重置')

if __name__=="__main__":
    global num,n1,n2,n3,chucheng,rac_orange
    num=n1=n2=n3=0
    chucheng=[]
    rac_orange=0.03
    root=Tk(className='三國志戰略版抽卡模擬器')#程序窗口名稱
    root.geometry('800x400')#程序窗口大小
    menu1=Menu(root)#主窗口
    filemenu1=Menu(menu1,tearoff=0)#子窗口1
    menu1.add_cascade(label='→菜單←',menu=filemenu1)
    filemenu1.add_command(label='出橙概率', command=do_job1)#label是名稱,command是函數名稱
    filemenu1.add_command(label='重置保底', command=do_job2)
    filemenu1.add_command(label='重置計數', command=do_job3) 
    root.config(menu=menu1)

    label=Label(root,text='點擊開始抽卡',bg='orange')
    label.pack()
    button1 = Button(root,text='抽一次',command=on_click_1)
    button1.place(x=300,y=30)
    button2 = Button(root,text='抽十次',command=on_click_2)
    button2.place(x=360,y=30)
    button3 = Button(root,text='抽一百次',command=on_click_3)
    button3.place(x=420,y=30)
    mainloop()

 

 

 

 

 

 僅供娛樂,哈哈

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM