Python實(shí)現(xiàn)原神抽卡的方法
更新時(shí)間:2021年12月06日 15:33:19 作者:qq_41256425
這篇文章主要為大家介紹了Python實(shí)現(xiàn)原神抽卡的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
話不多說,直接貼所有代碼
import random
import sys
import tkinter as tk # 導(dǎo)入一個(gè)第三方庫(kù),用于制作桌面軟件
import tkinter.font as tf
# 數(shù)據(jù)部分
R = {
"name": "R",
"color": "blue",
"size": "20",
"font": "微軟雅黑",
"data": ["冷刃", "黑纓槍", "白纓槍", "翡玉法球", "飛天大御劍", "暗鐵劍", "旅行劍", "鋼輪弓",
"吃魚虎刀", "沾染龍血的劍", "以理服人", "異世界行記", "甲級(jí)寶鈺", "翡玉法球"],
"person": []
}
SR = {
"name": "SR",
"color": "purple",
"size": "20",
"font": "微軟雅黑",
"data": ["腐殖之劍", "祭禮劍", "西風(fēng)劍", "試作斬巖", "笛劍", "螭骨劍", "鋼輪弓", "西風(fēng)獵弓",
"鋼輪弓", "絕弦", "祭禮弓", "萬國(guó)諸海圖譜", "匣里日月", "千巖古劍", "黑巖緋玉"],
"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 = "松籟響起之時(shí)"
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ù)抽獎(jiǎng)出的物品index獲取物品等級(jí)
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)前計(jì)數(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
}
# 建立一個(gè)主窗口 root
root = tk.Tk()
# 設(shè)置窗口標(biāo)題
root.title("原神模擬抽卡器")
# 設(shè)置單抽圖片
image_one = tk.PhotoImage(file="單抽圖片.png")
# 設(shè)置十連抽圖片
image_ten = tk.PhotoImage(file="十連抽.png")
# 在窗口上創(chuàng)建一個(gè)按鈕 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)建一個(gè)文本框,用于打印抽獎(jiǎ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ù),程序會(huì)運(yùn)行這里面的東西
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)
# 合并在一個(gè)總池,實(shí)現(xiàn)概率,可以通過算法實(shí)現(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])
# 運(yùn)行窗口
root.mainloop()
運(yùn)行效果

需要用到的兩張圖片


總結(jié)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
您可能感興趣的文章:
- Python爬蟲實(shí)現(xiàn)熱門電影信息采集
- SpringBoot調(diào)用python接口的實(shí)現(xiàn)步驟
- Python實(shí)現(xiàn)視頻中添加音頻工具詳解
- Python實(shí)現(xiàn)GIF動(dòng)圖以及視頻卡通化詳解
- Python實(shí)現(xiàn)照片卡通化
- Python+騰訊云服務(wù)器實(shí)現(xiàn)每日自動(dòng)健康打卡
- python?管理系統(tǒng)實(shí)現(xiàn)mysql交互的示例代碼
- Python實(shí)現(xiàn)圖片與視頻互轉(zhuǎn)代碼實(shí)戰(zhàn)(親測(cè)有效)
- Python實(shí)現(xiàn)如何根據(jù)文件后綴進(jìn)行分類
相關(guān)文章
淺談numpy數(shù)組中冒號(hào)和負(fù)號(hào)的含義
下面小編就為大家分享一篇淺談numpy數(shù)組中冒號(hào)和負(fù)號(hào)的含義,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-04-04
Python?matplotlib?plotly繪制圖表詳解
plotly本身是個(gè)生態(tài)非常復(fù)雜的繪圖工具,它對(duì)很多編程語言提供接口。交互式和美觀易用應(yīng)該是?Plotly?最大的優(yōu)勢(shì),而?Matplotlib?的特點(diǎn)則是可定制化程度高,但語法也相對(duì)難學(xué),各有優(yōu)缺點(diǎn)。本文將通過示例詳細(xì)講解二者是如何繪制圖表的,需要的可以參考一下2022-03-03
python正則表達(dá)中的re庫(kù)常用方法總結(jié)
這篇文章主要介紹了python正則表達(dá)中的re庫(kù)常用方法總結(jié)文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,感興趣的小伙伴可以參考一下2022-08-08
三步實(shí)現(xiàn)Django Paginator分頁(yè)的方法
這篇文章主要介紹了三步實(shí)現(xiàn)Django Paginator分頁(yè)的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06
python利用requests庫(kù)模擬post請(qǐng)求時(shí)json的使用教程
這篇文章主要介紹了python利用requests庫(kù)模擬post請(qǐng)求時(shí)json的使用 ,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-12-12

