Python實現(xiàn)原神抽卡的方法
更新時間:2021年12月06日 15:33:19 作者:qq_41256425
這篇文章主要為大家介紹了Python實現(xiàn)原神抽卡的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
話不多說,直接貼所有代碼
import random
import sys
import tkinter as tk # 導(dǎo)入一個第三方庫,用于制作桌面軟件
import tkinter.font as tf
# 數(shù)據(jù)部分
R = {
"name": "R",
"color": "blue",
"size": "20",
"font": "微軟雅黑",
"data": ["冷刃", "黑纓槍", "白纓槍", "翡玉法球", "飛天大御劍", "暗鐵劍", "旅行劍", "鋼輪弓",
"吃魚虎刀", "沾染龍血的劍", "以理服人", "異世界行記", "甲級寶鈺", "翡玉法球"],
"person": []
}
SR = {
"name": "SR",
"color": "purple",
"size": "20",
"font": "微軟雅黑",
"data": ["腐殖之劍", "祭禮劍", "西風(fēng)劍", "試作斬巖", "笛劍", "螭骨劍", "鋼輪弓", "西風(fēng)獵弓",
"鋼輪弓", "絕弦", "祭禮弓", "萬國諸海圖譜", "匣里日月", "千巖古劍", "黑巖緋玉"],
"person": ["香菱", "菲謝爾", "菲謝爾", "北斗", "芭芭拉", "北斗", "凝光", "托馬", "重云",
"砂糖", "煙緋", "安柏", "凱亞", "麗莎", "諾艾爾"]
}
SSR = {
"name": "SSR",
"color": "yellow",
"size": "20",
"font": "微軟雅黑",
"data": ["天空之卷", "四風(fēng)原典", "天空之傲", "天空之脊", "風(fēng)鷹劍", "風(fēng)鷹劍", "狼的末路"],
"person": ["迪盧克", "七七", "琴", "莫娜", "刻晴"]
}
ten_count = 0
ninety_count = 0
max_count = 0
person_up = "優(yōu)菈"
data_up = "松籟響起之時"
ALL = [R, SR, SSR]
tag_id = "0"
# 單抽
def one():
_res = get()
count_flush(_res["level"], _res["thing"])
insert_text(conf=_res["level"], message=_res["thing"])
text.insert("end", "\n")
text.see("end")
# 十連抽
def ten():
text.tag_add('tag', "end")
text.tag_config('tag', foreground="white")
text.insert("end", "\nstart\n", 'tag')
for i in range(10):
one()
text.insert("end", f"\nend{ten_count}/{ninety_count}/{max_count}\n", "tag")
text.see("end")
# 根據(jù)抽獎出的物品index獲取物品等級
def found(index):
for i in ALL:
if pool[index] in i["person"]:
return i
if pool[index] in i["data"]:
return i
# 每次抽卡后刷新當(dāng)前計數(shù)器
def count_flush(level, thing):
global ten_count
global ninety_count
global max_count
if level["name"] == "SR":
ten_count = 0
if level["name"] == "SSR":
ninety_count = 0
if level["name"] == "SSR" and ((thing in person_up) or (thing in data_up)):
max_count = 0
# 抽卡規(guī)則
def get():
global ten_count
global ninety_count
global max_count
level = None
ten_count += 1
ninety_count += 1
max_count += 1
if ten_count == 10:
level = SR
if ninety_count == 90:
level = SSR
if level is SR or level is SSR:
index = random.randrange(len(level[what]))
thing = level[what][index]
if max_count != ninety_count and level is SSR:
level = SSR
thing = person_up if what == "person" else data_up
if max_count == 180:
level = SSR
thing = person_up if what == "person" else data_up
if level is None:
index = random.randrange(len(pool))
level = found(index)
thing = pool[index]
return {
"level": level,
"thing": thing
}
# 建立一個主窗口 root
root = tk.Tk()
# 設(shè)置窗口標題
root.title("原神模擬抽卡器")
# 設(shè)置單抽圖片
image_one = tk.PhotoImage(file="單抽圖片.png")
# 設(shè)置十連抽圖片
image_ten = tk.PhotoImage(file="十連抽.png")
# 在窗口上創(chuàng)建一個按鈕 button,用于單抽,它依賴于父窗口root
button_one = tk.Button(root, text="單抽", image=image_one, command=one)
button_ten = tk.Button(root, text="十連抽", image=image_ten, command=ten)
# 布局創(chuàng)建的按鈕,rou代表行,column代表列
button_one.grid(row=0, column=0)
button_ten.grid(row=0, column=1)
# 創(chuàng)建一個文本框,用于打印抽獎日志
text = tk.Text(root, bg="black")
# columnspan代表合并兩列
text.grid(row=1, columnspan=2)
# 添加日志到Text框
def insert_text(message, conf):
global tag_id
# 設(shè)置字體大小和顏色
ft = tf.Font(family=conf["font"], size=conf["size"])
text.tag_add('tag'+tag_id, "end")
text.tag_config('tag'+tag_id, foreground=conf["color"], font=ft)
text.insert("end", message + "\n", "tag"+tag_id)
text.see("end")
tag_id = str(int(tag_id) + 1)
# mian函數(shù),程序會運行這里面的東西
if __name__ == '__main__':
# 修改為武器抽武器池
what = "角色"
if what == "角色":
what = "person"
if what == "武器":
what = "data"
if what not in ["data", "person"]:
sys.exit(1)
# 把up角色和武器加入池
SSR["data"].append(data_up)
SSR["person"].append(person_up)
# 合并在一個總池,實現(xiàn)概率,可以通過算法實現(xiàn),難得弄..
pool = list()
for i in range(90):
pool.extend(R["data"])
for i in range(10):
pool.extend(SR[what])
pool.extend(SSR[what])
# 運行窗口
root.mainloop()
運行效果

需要用到的兩張圖片


總結(jié)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
Python?matplotlib?plotly繪制圖表詳解
plotly本身是個生態(tài)非常復(fù)雜的繪圖工具,它對很多編程語言提供接口。交互式和美觀易用應(yīng)該是?Plotly?最大的優(yōu)勢,而?Matplotlib?的特點則是可定制化程度高,但語法也相對難學(xué),各有優(yōu)缺點。本文將通過示例詳細講解二者是如何繪制圖表的,需要的可以參考一下2022-03-03
三步實現(xiàn)Django Paginator分頁的方法
這篇文章主要介紹了三步實現(xiàn)Django Paginator分頁的方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06
python利用requests庫模擬post請求時json的使用教程
這篇文章主要介紹了python利用requests庫模擬post請求時json的使用 ,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-12-12

