laucher.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. import random
  2. import json
  3. import os
  4. import win32gui
  5. import sys
  6. import logging
  7. import rougetask
  8. import rougesetting
  9. import pygame
  10. import requests
  11. import concurrent.futures
  12. from datetime import datetime, timedelta
  13. from game import rogue_control
  14. from game.rogue_control import Control
  15. from game.algo import rougeGen
  16. from game.file_loader.fileLoader import load_json, load_png, save_encrypt_single_rouge_file, load_rouge_data
  17. from game.algo import utils as util
  18. from game.algo import rougeGen as RG
  19. from game.const import window as W, color as C, game as G
  20. from game.const import rouge as R
  21. from game.music import music_loader
  22. from game.sound import sound_player
  23. from game.ui.menu.component import PygameButton, PygameButtonBackIMG
  24. current_folder_path = os.getcwd()
  25. def current_lv(lv):
  26. lv_list = R.lv_list
  27. if lv >= sum(lv_list):
  28. return "--"
  29. for k in range(0, 14):
  30. if sum(lv_list[:k]) <= lv < sum(lv_list[:k + 1]):
  31. return str(sum(lv_list[:k + 1]) - lv)
  32. def check_rouge_ob_data(data):
  33. hero_data_dic = {
  34. "Fox": {"exp": 0, "lv": 1}, "Boboli": {"exp": 0, "lv": 1}, "Naruto_old": {"exp": 0, "lv": 1},
  35. "Asha": {"exp": 0, "lv": 1}, "Maria": {"exp": 0, "lv": 1}, "Surprise": {"exp": 0, "lv": 1}
  36. }
  37. err_cnt = 0
  38. for k, v in hero_data_dic.items():
  39. if k not in data.keys():
  40. data[k] = v
  41. err_cnt += 1
  42. print(f"缺失{k}数据, 正在补充...")
  43. if err_cnt > 0:
  44. save_encrypt_single_rouge_file(data, "rougeOB")
  45. class Menu:
  46. def __init__(self, screen, bg_image_path=None):
  47. self.screen = screen
  48. self.buttons = []
  49. self.current_hero = "Fox"
  50. self.current_difficulty = "Easy"
  51. self.is_random = False # 随机选择角色
  52. if bg_image_path:
  53. img = pygame.image.load(bg_image_path).convert()
  54. self.bg_image = pygame.transform.scale(img, screen.get_size())
  55. else:
  56. self.bg_image = None
  57. self._init_data()
  58. self._create_buttons()
  59. def _init_data(self):
  60. rougeOB_data = {}
  61. rougeOB_achivements = []
  62. with open("config.json", "r", encoding="utf-8") as json_file:
  63. mapsetdata = json.load(json_file)
  64. R.rouge_hero = mapsetdata["your_hero"]
  65. self.current_hero = mapsetdata["your_hero"]
  66. R.difficulty = mapsetdata["rogue_difficulty"]
  67. self.current_difficulty = mapsetdata["rogue_difficulty"]
  68. print(mapsetdata["rogue_difficulty"])
  69. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  70. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  71. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  72. rouge_file_path = os.path.join(qqtpve_folder, "rougeOB.rougedata") # 构建文件路径
  73. rouge_achivements_file_path = os.path.join(qqtpve_folder, "rougeOB_achievement.rougedata") # 构建成就文件路径
  74. old_file_path = os.path.join(qqtpve_folder, "rouge.json") # 构建文件路径
  75. old_achivements_file_path = os.path.join(qqtpve_folder, "rouge_achievement.json") # 构建成就文件路径
  76. rouge_task_file_path = os.path.join(qqtpve_folder, "rougeOB_task.rougedata") # 构建任务文件路径
  77. last_game_file_path = os.path.join(qqtpve_folder, "rougeOBLastGame.rougedata") # 构建存档文件路径
  78. other_file_path = os.path.join(qqtpve_folder, "rougeOBOther.rougedata") # 构建其他文件路径
  79. # 杂项第一次打开
  80. if not os.path.exists(other_file_path):
  81. rougeOB_other_data = {"Bomb": [],
  82. "Pet": [],
  83. "Hat": [],
  84. "LastRandom": 0,
  85. "Other": []}
  86. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  87. # 正常打开
  88. else:
  89. rougeOB_other_data = load_rouge_data(other_file_path)
  90. if 'Cursor_Skin' not in rougeOB_other_data.keys():
  91. rougeOB_other_data['Cursor_Skin'] = "fire_cursor"
  92. R.cursor_skin = "fire_cursor"
  93. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  94. else:
  95. R.cursor_skin = rougeOB_other_data['Cursor_Skin']
  96. if 'Bomb_Skin' not in rougeOB_other_data.keys():
  97. rougeOB_other_data['Bomb_Skin'] = "bomb1"
  98. R.bomb_skin = "bomb1"
  99. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  100. else:
  101. R.bomb_skin = rougeOB_other_data['Bomb_Skin']
  102. # 第一次打开
  103. if not os.path.exists(rouge_task_file_path):
  104. rougeOB_task_data = {
  105. "1": {"task": "击杀5只命运维系者", "reward": "800经验", "process": 0, "finish": 5, "last_finish": 1970,
  106. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  107. "2": {"task": "击杀3只渊烬龙王", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  108. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  109. "3": {"task": "到达3-1十次", "reward": "800经验", "process": 0, "finish": 10, "last_finish": 1970,
  110. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  111. "4": {"task": "击杀5只因果阅律者", "reward": "800经验", "process": 0, "finish": 5, "last_finish": 1970,
  112. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  113. "5": {"task": "完成20次挑衅敌人", "reward": "800经验", "process": 0, "finish": 20, "last_finish": 1970,
  114. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  115. "6": {"task": "使用小倩到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  116. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  117. "7": {"task": "使用波波丽到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  118. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  119. "8": {"task": "使用火影到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  120. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  121. "9": {"task": "使用阿莎到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  122. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  123. "10": {"task": "使用玛莉亚到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  124. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  125. "11": {"task": "到达4-1一次", "reward": "800经验", "process": 0, "finish": 1, "last_finish": 1970,
  126. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  127. "12": {"task": "累积使用20次复活卡", "reward": "800经验", "process": 0, "finish": 20, "last_finish": 1970,
  128. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  129. "today": {"task": "进行一盘游戏并到达2-1", "reward": "50经验", "process": 0, "finish": 1,
  130. "last_finish": "1970-1-1", "reward_exp": 50, "hero": "Fox", "rewarded": True}}
  131. save_encrypt_single_rouge_file(rougeOB_task_data, "rougeOB_task")
  132. # 正常打开
  133. else:
  134. rougeOB_task_data = load_rouge_data(rouge_task_file_path)
  135. now = datetime.now()
  136. # 格式化年月日
  137. year = now.strftime("%Y")
  138. month = now.strftime("%m")
  139. day = now.strftime("%d")
  140. # 移除月份和日期的前导零(如果有)
  141. month = month.lstrip("0")
  142. day = day.lstrip("0")
  143. R.today_datetime["year"] = int(year)
  144. R.today_datetime["month"] = int(month)
  145. R.today_datetime["day"] = int(day)
  146. try:
  147. if len(rougeOB_task_data[str(month)]["last_finish"]) > 4: # 防一手格式错误
  148. rougeOB_task_data[str(month)]["last_finish"] = rougeOB_task_data[str(month)]["last_finish"][0:4]
  149. except:
  150. pass
  151. if int(rougeOB_task_data[str(month)]["last_finish"]) < int(year):
  152. rougeOB_task_data[str(month)]["process"] = 0
  153. rougeOB_task_data[str(month)]["last_finish"] = year
  154. rougeOB_task_data[str(month)]["rewarded"] = False
  155. if rougeOB_task_data["today"]["last_finish"] != year + "-" + month + "-" + day:
  156. rougeOB_task_data["today"]["process"] = 0
  157. rougeOB_task_data["today"]["last_finish"] = year + "-" + month + "-" + day
  158. rougeOB_task_data["today"]["rewarded"] = False
  159. save_encrypt_single_rouge_file(rougeOB_task_data, "rougeOB_task")
  160. # 第一次打开
  161. if not os.path.exists(rouge_file_path):
  162. # 若参与过第一轮beta测试
  163. if os.path.exists(old_file_path):
  164. # 备份旧文件
  165. old_json = load_json(old_file_path)
  166. rougeOB_data = {"Fox": {"exp": old_json["Fox"]["exp"], "lv": old_json["Fox"]["lv"]},
  167. "Boboli": {"exp": old_json["Boboli"]["exp"], "lv": old_json["Boboli"]["exp"]},
  168. "Naruto_old": {"exp": 0, "lv": 1},
  169. "Asha": {"exp": old_json["Naruto_old"]["exp"], "lv": old_json["Naruto_old"]["exp"]},
  170. "Maria": {"exp": 0, "lv": 1},
  171. "Surprise": {"exp": 0, "lv": 1}}
  172. print("等级数据继承成功")
  173. else:
  174. rougeOB_data = {
  175. "Fox": {"exp": 0, "lv": 1},
  176. "Boboli": {"exp": 0, "lv": 1},
  177. "Naruto_old": {"exp": 0, "lv": 1},
  178. "Asha": {"exp": 0, "lv": 1},
  179. "Maria": {"exp": 0, "lv": 1},
  180. "Surprise": {"exp": 0, "lv": 1}
  181. }
  182. save_encrypt_single_rouge_file(rougeOB_data, "rougeOB")
  183. # 正常打开
  184. else:
  185. rougeOB_data = load_rouge_data(rouge_file_path)
  186. # =========================================================================================
  187. util.load_online_config()
  188. if G.UID == "" and G.USERNAME == "":
  189. # username = input("请输入昵称: ").strip()
  190. # password = input("请输入密码: ").strip()
  191. util.register()
  192. new_info = rougeOB_data
  193. new_info["record"] = "null"
  194. result = util.update_profile(G.UID, new_info, G.PASSWORD)
  195. print(result.get('message', '未知错误'))
  196. is_online = util.try_login()
  197. if is_online:
  198. rougeOB_data = util.get_online_data()
  199. # =========================================================================================
  200. check_rouge_ob_data(rougeOB_data)
  201. print(rougeOB_data)
  202. for hero in ["Fox", "Boboli", "Naruto_old", "Asha", "Maria"]:
  203. rougeOB_data[hero]["lv"] = R.current_lv(rougeOB_data[hero]["exp"])
  204. self.Fox_info = "小倩: 等级" + str(rougeOB_data["Fox"]["lv"]) + ", 升级还需经验:" + current_lv(
  205. rougeOB_data["Fox"]["exp"]) + "\n技能: 自身血量减少1则糖泡伤害增加" + str(R.FoxSkill(rougeOB_data["Fox"]["lv"]))
  206. self.Boboli_info = "波波丽: 等级" + str(rougeOB_data["Boboli"]["lv"]) + ", 升级还需经验:" + current_lv(
  207. rougeOB_data["Boboli"]["exp"]) + "\n技能: 每次攻击额外造成" + str(
  208. int(R.BoboliSkill(rougeOB_data["Boboli"]["lv"]) * 100)) + "%真实伤害"
  209. self.Naruto_old_info = "火影: 等级" + str(rougeOB_data["Naruto_old"]["lv"]) + ", 升级还需经验:" + current_lv(
  210. rougeOB_data["Naruto_old"]["exp"]) + "\n技能: 首次攻击每只怪物时攻击力变为" + str(
  211. int(R.Naruto_oldSkill(rougeOB_data["Naruto_old"]["lv"]) * 100)) + "%"
  212. self.Asha_info = "阿莎: 等级" + str(rougeOB_data["Asha"]["lv"]) + ", 升级还需经验:" + current_lv(
  213. rougeOB_data["Asha"]["exp"]) + "\n技能: 每次糖泡造成伤害恢复血量" + str(
  214. R.AshaSkill(rougeOB_data["Asha"]["lv"]) * 100) + "%"
  215. self.Maria_info = "玛莉亚: 等级" + str(rougeOB_data["Maria"]["lv"]) + ", 升级还需经验:" + current_lv(
  216. rougeOB_data["Maria"]["exp"]) + "\n技能: 每次造成伤害降低怪物近身" + str(
  217. R.MariaSkill(rougeOB_data["Maria"]["lv"]) * 100) + "%(最高50%)与" + str(
  218. R.MariaSkill2(rougeOB_data["Maria"]["lv"])) + "防御"
  219. # 第一次打开
  220. if not os.path.exists(rouge_achivements_file_path):
  221. # 若参与过第一轮beta测试
  222. '''
  223. if os.path.exists(old_achivements_file_path):
  224. # 备份旧文件
  225. old_achivements_json = load_json(old_achivements_file_path)
  226. rougeOB_achivements = old_achivements_json
  227. print("成就数据继承成功")
  228. else:
  229. rougeOB_achivements = []
  230. '''
  231. rougeOB_achivements = []
  232. save_encrypt_single_rouge_file(rougeOB_achivements, "rougeOB_achievement")
  233. # 正常打开
  234. else:
  235. rougeOB_achivements = load_rouge_data(rouge_achivements_file_path)
  236. # for ch in rougeOB_achivements:
  237. # print(ch)
  238. max_level = 0
  239. max_level_hero = "Fox"
  240. max_diff = "Easy"
  241. max_diff_num = 1
  242. self.hero_dic = {"Fox": "小倩", "Boboli": "波波丽", "Naruto_old": "火影", "Asha": "阿莎", "Maria": "玛莉亚",
  243. "Surprise": "???"}
  244. self.diff_dic = {"Easy": "简单", "Normal": "困难", "Hell": "炼狱", "Hell+": "炼狱+"}
  245. diff_num = {"Easy": 1, "Normal": 2, "Hell": 3, "Hell+": 4}
  246. diff_status = {"Easy": 0, "Normal": 0, "Hell": 0, "Hell+": 0}
  247. for data in rougeOB_achivements:
  248. if diff_num[data["DIFF"]] > max_diff_num:
  249. max_level = data["CL"]
  250. max_level_hero = data["HERO"]
  251. max_diff = data["DIFF"]
  252. max_diff_num = diff_num[data["DIFF"]]
  253. if diff_num[data["DIFF"]] == max_diff_num:
  254. if data["CL"] > max_level:
  255. max_level = data["CL"]
  256. max_level_hero = data["HERO"]
  257. if data["CL"] == 20:
  258. diff_status[data["DIFF"]] = 2
  259. if max_level > 0:
  260. self.record_text = f"最高挑战纪录: 通关<{self.diff_dic[max_diff]}{(max_level - 1) // 5 + 1}-{(max_level - 1) % 5 + 1}>; 使用英雄: {self.hero_dic[max_level_hero]}"
  261. else:
  262. self.record_text = "暂无挑战记录"
  263. if max_diff == "Hell+":
  264. R.pass_status["Easy"] = 1
  265. R.pass_status["Normal"] = 1
  266. R.pass_status["Hell"] = 1
  267. if max_level >= 15:
  268. R.pass_status["Hell+"] = 1
  269. elif max_diff == "Hell":
  270. R.pass_status["Easy"] = 1
  271. R.pass_status["Normal"] = 1
  272. # R.cursor_skin = "fire_cursor_kubi"
  273. if max_level >= 15:
  274. R.pass_status["Hell"] = 1
  275. # R.cursor_skin = "fire_cursor_gold_kubi"
  276. elif max_diff == "Normal":
  277. R.pass_status["Easy"] = 1
  278. # R.cursor_skin = "fire_cursor2"
  279. if max_level >= 15:
  280. R.pass_status["Normal"] = 1
  281. # R.cursor_skin = "fire_cursor_kubi"
  282. else:
  283. if max_level >= 15:
  284. R.pass_status["Easy"] = 1
  285. # R.cursor_skin = "fire_cursor2"
  286. for dif in ["Easy", "Normal", "Hell", "Hell+"]:
  287. if diff_status[dif] == 2:
  288. R.pass_status[dif] = 2
  289. def _create_buttons(self):
  290. # 主界面按钮
  291. self.buttons.clear()
  292. # "进入游戏"
  293. # self.buttons.append(PygameButton(self.screen, "进入游戏", 0.5, 0.29, 32, "#e1bd48", action=self._start_game, is_bold=True))
  294. self.buttons.append(PygameButtonBackIMG(self.screen, 0.5, 0.3, "res/ui/game/start_button_0.png", "res/ui/game/start_button_1.png", action=self._start_game, anchor='center'))
  295. # "继续游戏"
  296. if os.path.exists(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")):
  297. last = load_rouge_data(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
  298. lvl = ((last["current_level"] + 2) // 2 - 1) // 5 + 1
  299. stage = ((last["current_level"] + 2) // 2 - 1) % 5 + 1
  300. text_c = f"继续游戏 (关卡: {lvl}-{stage}) \n (难度: {self.diff_dic[last['difficulty']]}; 英雄: {self.hero_dic[last['rouge_hero']]})"
  301. self.buttons.append(PygameButton(self.screen, text_c, 0.5, 0.44, 18, "#e1bd48", action=lambda: self._continue_game(last), is_bold=True, bg_alpha=191))
  302. # 任务系统
  303. self.buttons.append(
  304. PygameButton(self.screen, "任务系统", 0.16, 0.16, 24, "#e1bd48", action=self._open_task, is_bold=True, fix_shape=(120,30), bg_alpha=127))
  305. # 陈列馆
  306. self.buttons.append(
  307. PygameButton(self.screen, "陈列馆", 0.16, 0.28, 24, "#e1bd48", action=self._open_setting, is_bold=True, fix_shape=(120,30), bg_alpha=127))
  308. # 难度选择
  309. last_diff = {"Easy": "Easy", "Normal": "Easy", "Hell": "Normal", "Hell+": "Hell"}
  310. for diff, rel in [("Easy", 0.1), ("Normal", 0.18), ("Hell", 0.26), ("Hell+", 0.34)]:
  311. if diff == R.difficulty:
  312. text = f"★ 当前难度: {self.diff_dic[diff]}"
  313. color = "#c7a44f"
  314. self.buttons.append(PygameButton(self.screen, text, 0.75, rel, 13, color, anchor="topleft", is_bold=True, fix_shape=(120,15), bg_alpha=191))
  315. else:
  316. enabled = R.pass_status.get(last_diff[diff], 0) > 0
  317. if diff == "Easy":
  318. text = f"● 选择{self.diff_dic[diff]}难度"
  319. color = "#99be7f"
  320. action = lambda d=diff: self._choose_diff(d)
  321. self.buttons.append(
  322. PygameButton(self.screen, text, 0.75, rel, 13, color, action=action, anchor="topleft", is_bold=True, fix_shape=(120,15), bg_alpha=191))
  323. else:
  324. text = f"● 选择{self.diff_dic[diff]}难度" if enabled else f"○ {self.diff_dic[diff]}难度(未解锁)"
  325. color = "#99be7f" if enabled else "#55516d"
  326. if enabled:
  327. action = lambda d=diff: self._choose_diff(d)
  328. self.buttons.append(PygameButton(self.screen, text, 0.75, rel, 13, color, action=action, anchor="topleft", is_bold=True, fix_shape=(120,15), bg_alpha=191))
  329. else:
  330. self.buttons.append(PygameButton(self.screen, text, 0.75, rel, 13, color, fg_color=(255, 255, 255), anchor="topleft", is_bold=False, fix_shape=(120,15), bg_alpha=63))
  331. # ================================= 英雄选择 =================================
  332. heroes = ["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Surprise"]
  333. x_position = 0.1
  334. y_positions = [0.64, 0.70, 0.76, 0.82, 0.88, 0.49]
  335. for hero, y in zip(heroes, y_positions):
  336. if not self.is_random and hero == R.rouge_hero:
  337. text = f"★ 使用{self.hero_dic[hero]}"
  338. self.buttons.append(PygameButton(self.screen, text, x_position, y, 12, "#c7a44f", action=lambda h=hero: self._choose_hero(h), anchor="topleft", is_bold=True, fix_shape=(80,15), bg_alpha=191))
  339. else:
  340. text = f"● 选择{self.hero_dic[hero]}"
  341. self.buttons.append(PygameButton(self.screen, text, x_position, y, 12, "#99be7f", action=lambda h=hero: self._choose_hero(h), anchor="topleft", is_bold=True, fix_shape=(80,15), bg_alpha=127))
  342. # 随机开局
  343. if self.is_random:
  344. self.buttons.append(PygameButton(self.screen, "★ 使用随机", x_position, 0.94, 12, "#c7a44f", action=lambda: self._choose_hero("Random"), anchor="topleft", is_bold=True, fix_shape=(80,15), bg_alpha=127))
  345. else:
  346. self.buttons.append(PygameButton(self.screen, "● 随机开局", x_position, 0.94, 12, "#99be7f", action=lambda: self._choose_hero("Random"), anchor="topleft", is_bold=True, fix_shape=(80,15), bg_alpha=127))
  347. # 英雄信息提示
  348. infos = [getattr(self, attr) for attr in ['Fox_info', 'Boboli_info', 'Naruto_old_info', 'Asha_info', 'Maria_info']]
  349. base_heroes = ["Fox", "Boboli", "Naruto_old", "Asha", "Maria"]
  350. if not self.is_random:
  351. for hero, info, y in zip(base_heroes, infos, y_positions):
  352. if hero == R.rouge_hero:
  353. self.buttons.append(PygameButton(self.screen, info, 0.32, y-0.03, 14, "#d7b8da", fg_color=(0, 0, 0), anchor="topleft", bg_alpha=127))
  354. # ==========================================================================
  355. # 最高记录
  356. record = getattr(self, 'record_text', "暂无挑战记录")
  357. self.buttons.append(PygameButton(self.screen, record, 0.5, 0.56, 14, "#7E354D", fg_color=(255, 255, 255), bg_alpha=191))
  358. # 各个按钮动作方法
  359. def _start_game(self):
  360. rougeGen.main_func()
  361. game = Control(
  362. screen=self.screen,
  363. is_continue=False
  364. )
  365. game.update()
  366. def _continue_game(self, last):
  367. self.read_continue_data(last)
  368. game = rogue_control.Control(
  369. screen=self.screen,
  370. is_continue=True
  371. )
  372. game.update()
  373. def _open_task(self):
  374. from rougetask import Task
  375. Task(pygame.display.set_mode((800, 600)))
  376. def _open_setting(self):
  377. from rougesetting import Setting
  378. Setting(pygame.display.set_mode((800, 600)))
  379. def _choose_diff(self, diff):
  380. R.difficulty = diff
  381. with open("config.json", "r", encoding="utf-8") as json_file:
  382. mapsetdata = json.load(json_file)
  383. mapsetdata["map_set"] = "rogueMapSet"
  384. mapsetdata["rogue_difficulty"] = diff
  385. with open("config.json", "w", encoding="utf-8") as json_file:
  386. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  387. self._create_buttons()
  388. def _choose_hero(self, hero):
  389. if hero == "Random":
  390. hero = random.choice(["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Surprise"])
  391. self.is_random = True
  392. else:
  393. self.is_random = False
  394. R.rouge_hero = hero
  395. self.current_hero = hero
  396. with open("config.json", "r", encoding="utf-8") as json_file:
  397. mapsetdata = json.load(json_file)
  398. mapsetdata["map_set"] = "rogueMapSet"
  399. mapsetdata["your_hero"] = hero
  400. with open("config.json", "w", encoding="utf-8") as json_file:
  401. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  402. self._create_buttons()
  403. def run(self):
  404. clock = pygame.time.Clock()
  405. while True:
  406. for event in pygame.event.get():
  407. if event.type == pygame.QUIT:
  408. pygame.quit()
  409. sys.exit()
  410. for btn in self.buttons:
  411. btn.handle_event(event)
  412. if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
  413. # 看看有没有按钮自己处理了这次点击
  414. if not any(btn.bg_rect.collidepoint(event.pos) for btn in self.buttons):
  415. sound_player.play("uiFail")
  416. # 先画背景
  417. # self.screen.fill((30,30,30))
  418. if self.bg_image:
  419. self.screen.blit(self.bg_image, (0, 0))
  420. else:
  421. self.screen.fill((60, 90, 60))
  422. # 再画按钮
  423. for btn in self.buttons:
  424. btn.draw()
  425. pygame.display.flip()
  426. clock.tick(60)
  427. # 读取上次存档
  428. def read_continue_data(self, last_data):
  429. R.continuing_game = True
  430. G.CURRENT_LEVEL = last_data["current_level"]
  431. R.map_json_dic = last_data["map_json_dic"]
  432. R.central_mapset = last_data["central_mapset"]
  433. R.difficulty = last_data["difficulty"]
  434. R.today_datetime = last_data["today_datetime"]
  435. R.task_RougeTreasureDestinyElite = last_data["task_RougeTreasureDestinyElite"]
  436. R.task_MineCFireDragonBoss = last_data["task_MineCFireDragonBoss"]
  437. R.task_RougeTreasureDestinyWizard = last_data["task_RougeTreasureDestinyWizard"]
  438. R.task_combat = last_data["task_combat"]
  439. R.task_revival = last_data["task_revival"]
  440. R.rouge_data = last_data["rouge_data"]
  441. R.rouge_hero = last_data["rouge_hero"]
  442. R.rouge_lv = last_data["rouge_lv"]
  443. R.rouge_exp = last_data["rouge_exp"]
  444. R.game_exp = last_data["game_exp"]
  445. R.rouge_story = last_data["rouge_story"]
  446. R.rouge_theme_1 = last_data["rouge_theme_1"]
  447. R.rouge_theme_2 = last_data["rouge_theme_2"]
  448. R.rouge_theme_3 = last_data["rouge_theme_3"]
  449. R.rouge_theme_4 = last_data["rouge_theme_4"]
  450. R.rouge_destiny = last_data["rouge_destiny"]
  451. R.coin = last_data["coin"]
  452. R.general_mon_dic = last_data["general_mon_dic"]
  453. R.story_eden = last_data["story_eden"]
  454. R.story_destiny = last_data["story_destiny"]
  455. R.current_standard_HP = last_data["current_standard_HP"]
  456. R.current_standard_damage = last_data["current_standard_damage"]
  457. R.current_standard_speed = last_data["current_standard_speed"]
  458. R.current_standard_defense = last_data["current_standard_defense"]
  459. R.current_standard_bomb = last_data["current_standard_bomb"]
  460. R.se_district = last_data["se_district"]
  461. R.battle_district = last_data["battle_district"]
  462. R.monster_defense_delta = last_data["monster_defense_delta"]
  463. R.monster_HP_rate = last_data["monster_HP_rate"]
  464. R.player_bomb_self_damage_reduce_rate = last_data["player_bomb_self_damage_reduce_rate"]
  465. R.slow_immune = last_data["slow_immune"]
  466. R.reverse_immune = last_data["reverse_immune"]
  467. R.root_immune = last_data["root_immune"]
  468. R.stun_immune = last_data["stun_immune"]
  469. R.random_dmg = last_data["random_dmg"]
  470. R.show_cursor = last_data["show_cursor"]
  471. R.last_item = last_data["items"]
  472. if os.path.exists(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")):
  473. os.remove(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
  474. print("已读取,清除数据!!!!!!!!!!!!!")
  475. else:
  476. print("???")
  477. def show_prompt():
  478. """显示提示框,询问用户如何操作"""
  479. import tkinter as tk
  480. from tkinter import messagebox
  481. def close_existing():
  482. root.destroy()
  483. sys.exit()
  484. root = tk.Tk()
  485. root.withdraw() # 隐藏主窗口
  486. if messagebox.askyesno("进程已打开", "已有一个游戏进程正在运行。请关闭后再运行!"):
  487. close_existing()
  488. # 获取所有窗口句柄
  489. def get_all_windows():
  490. windows = []
  491. def enum_windows_proc(hwnd, _):
  492. if win32gui.IsWindowVisible(hwnd):
  493. window_text = win32gui.GetWindowText(hwnd)
  494. if window_text:
  495. windows.append(window_text)
  496. return True
  497. win32gui.EnumWindows(enum_windows_proc, None)
  498. return windows
  499. # 检测窗口是否存在
  500. def check_window_exists():
  501. windows = get_all_windows()
  502. # print(windows)
  503. for window in windows:
  504. if "QQTRogue" in window and "永恒" in window and "100の雨女" in window and "756422783" in window and "擅自售卖皆属剽窃" in window:
  505. return True
  506. return False
  507. class Launcher:
  508. def __init__(self):
  509. pygame.init()
  510. self.screen = pygame.display.set_mode(W.WINDOW_SIZE)
  511. pygame.display.set_caption(W.WINDOW_CAPTION)
  512. self.cfg_json = {}
  513. self.music_volume = 0.7
  514. self.display_flags = 0
  515. self.init_config()
  516. self.init_window()
  517. # 预加载资源
  518. # self.preload_resources()
  519. # 启动菜单
  520. music_loader.play("rogue_menu.mp3", self.music_volume)
  521. self.menu = Menu(self.screen, bg_image_path="res/ui/game/rogue_menu.png")
  522. self.menu.run()
  523. def init_config(self):
  524. try:
  525. with open("config.json", encoding="utf-8") as f:
  526. self.cfg_json = json.load(f)
  527. except json.JSONDecodeError:
  528. with open("config.json", encoding="utf-8_sig") as f:
  529. self.cfg_json = json.load(f)
  530. self.music_volume = self.cfg_json["music_volume"]
  531. if not self.cfg_json["frame_screen"]:
  532. self.display_flags = pygame.NOFRAME
  533. if self.cfg_json["full_screen"]:
  534. self.display_flags = pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF
  535. try:
  536. if self.cfg_json["v_sync"] and self.cfg_json["frame_screen"] and not self.cfg_json["full_screen"]:
  537. self.display_flags = pygame.HWSURFACE | pygame.DOUBLEBUF
  538. # self.display_flags = pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.OPENGL
  539. elif self.cfg_json["v_sync"] and not self.cfg_json["frame_screen"]:
  540. self.display_flags |= pygame.HWSURFACE | pygame.DOUBLEBUF
  541. elif self.cfg_json["v_sync"] and self.cfg_json["full_screen"]:
  542. self.display_flags = pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF
  543. except Exception as e:
  544. print(e)
  545. def init_window(self):
  546. self.screen = pygame.display.set_mode(W.WINDOW_SIZE, flags=self.display_flags)
  547. pygame.display.set_icon(pygame.image.load("res/img/ui/icon.png").convert_alpha())
  548. for i in range(10):
  549. file_name = "itemNum_0_" + str(i) + ".png"
  550. img = pygame.image.load("res/img/ui/number/" + file_name).convert_alpha()
  551. G.NUMBER_IMG.append(img)
  552. def preload_resources(self):
  553. with concurrent.futures.ThreadPoolExecutor() as executor:
  554. executor.submit(Control.preload)
  555. if __name__ == "__main__":
  556. # # 定义日志文件路径
  557. # # log_file_path = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "program.log")
  558. # log_file_path = os.path.join(os.getcwd(), "program.log")
  559. # # 打开日志文件并重定向 stdout
  560. # log_file = open(log_file_path, 'a', encoding='utf-8') # 'a' 是追加模式
  561. # # 重定向 sys.stdout(print 函数输出)
  562. # sys.stdout = log_file
  563. # # 重定向 sys.stderr(报错信息)
  564. # sys.stderr = log_file
  565. print("=========== start ==============")
  566. if check_window_exists():
  567. show_prompt()
  568. Launcher()