laucher.py 28 KB

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