import random import json import os import win32gui import sys import time import logging import rougetask import rougesetting import pygame import requests import threading import concurrent.futures import tkinter as tk from datetime import datetime, timedelta from game import rogue_control from game.rogue_control import Control from game.algo import rougeGen from game.file_loader.fileLoader import load_json, load_png, save_encrypt_single_rouge_file, load_rouge_data from game.algo import utils as util from game.algo import rougeGen as RG from game.const import window as W, color as C, game as G from game.const import rouge as R from game.music import music_loader from game.sound import sound_player from game.ui.menu.component import PygameButton, PygameButtonBackIMG, Particle from game.utils import local_data_manager as DM current_folder_path = os.getcwd() def current_lv(lv): lv_list = R.lv_list if lv >= sum(lv_list): return "--" for k in range(0, 14): if sum(lv_list[:k]) <= lv < sum(lv_list[:k + 1]): return str(sum(lv_list[:k + 1]) - lv) def check_rouge_ob_data(data): hero_data_dic = { "Fox": {"exp": 0, "lv": 1}, "Boboli": {"exp": 0, "lv": 1}, "Naruto_old": {"exp": 0, "lv": 1}, "Asha": {"exp": 0, "lv": 1}, "Maria": {"exp": 0, "lv": 1}, "Surprise": {"exp": 0, "lv": 1} } err_cnt = 0 for k, v in hero_data_dic.items(): if k not in data.keys(): data[k] = v err_cnt += 1 print(f"缺失{k}数据, 正在补充...") if err_cnt > 0: save_encrypt_single_rouge_file(data, "rougeOB") class Menu: def __init__(self, screen, bg_image_path=None): self.screen = screen self.buttons = [] self.particles = [] # 粒子列表 self.current_hero = "Fox" self.current_difficulty = "Easy" self.is_random = False # 随机选择角色 if bg_image_path: img = pygame.image.load(bg_image_path).convert() self.bg_image = pygame.transform.scale(img, screen.get_size()) else: self.bg_image = None W.MENU = self self._init_data() self._create_buttons() def _init_data(self): with open("config.json", "r", encoding="utf-8") as json_file: mapsetdata = json.load(json_file) R.rouge_hero = mapsetdata["your_hero"] self.current_hero = mapsetdata["your_hero"] R.difficulty = mapsetdata["rogue_difficulty"] self.current_difficulty = mapsetdata["rogue_difficulty"] print(mapsetdata["rogue_difficulty"]) user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径 qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径 os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建 rouge_file_path = os.path.join(qqtpve_folder, "rougeOB.rougedata") # 构建文件路径 rouge_achivements_file_path = os.path.join(qqtpve_folder, "rougeOB_achievement.rougedata") # 构建成就文件路径 old_file_path = os.path.join(qqtpve_folder, "rouge.json") # 构建文件路径 old_achivements_file_path = os.path.join(qqtpve_folder, "rouge_achievement.json") # 构建成就文件路径 rouge_task_file_path = os.path.join(qqtpve_folder, "rougeOB_task.rougedata") # 构建任务文件路径 last_game_file_path = os.path.join(qqtpve_folder, "rougeOBLastGame.rougedata") # 构建存档文件路径 other_file_path = os.path.join(qqtpve_folder, "rougeOBOther.rougedata") # 构建其他文件路径 # 杂项第一次打开 if not os.path.exists(other_file_path): rougeOB_other_data = {"Bomb": [], "Pet": [], "Hat": [], "LastRandom": 0, "Other": []} save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther") # 正常打开 else: rougeOB_other_data = load_rouge_data(other_file_path) if 'Cursor_Skin' not in rougeOB_other_data.keys(): rougeOB_other_data['Cursor_Skin'] = "fire_cursor" R.cursor_skin = "fire_cursor" save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther") else: R.cursor_skin = rougeOB_other_data['Cursor_Skin'] if 'Bomb_Skin' not in rougeOB_other_data.keys(): rougeOB_other_data['Bomb_Skin'] = "bomb1" R.bomb_skin = "bomb1" save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther") else: R.bomb_skin = rougeOB_other_data['Bomb_Skin'] # 第一次打开 if not os.path.exists(rouge_task_file_path): rougeOB_task_data = { "1": {"task": "击杀5只命运维系者", "reward": "800经验", "process": 0, "finish": 5, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True}, "2": {"task": "击杀3只渊烬龙王", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True}, "3": {"task": "到达3-1十次", "reward": "800经验", "process": 0, "finish": 10, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True}, "4": {"task": "击杀5只因果阅律者", "reward": "800经验", "process": 0, "finish": 5, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True}, "5": {"task": "完成20次挑衅敌人", "reward": "800经验", "process": 0, "finish": 20, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True}, "6": {"task": "使用小倩到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True}, "7": {"task": "使用波波丽到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True}, "8": {"task": "使用火影到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True}, "9": {"task": "使用阿莎到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True}, "10": {"task": "使用玛莉亚到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True}, "11": {"task": "到达4-1一次", "reward": "800经验", "process": 0, "finish": 1, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True}, "12": {"task": "累积使用20次复活卡", "reward": "800经验", "process": 0, "finish": 20, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True}, "today": {"task": "进行一盘游戏并到达2-1", "reward": "50经验", "process": 0, "finish": 1, "last_finish": "1970-1-1", "reward_exp": 50, "hero": "Fox", "rewarded": True}} save_encrypt_single_rouge_file(rougeOB_task_data, "rougeOB_task") # 正常打开 else: rougeOB_task_data = load_rouge_data(rouge_task_file_path) now = datetime.now() # 格式化年月日 year = now.strftime("%Y") month = now.strftime("%m") day = now.strftime("%d") # 移除月份和日期的前导零(如果有) month = month.lstrip("0") day = day.lstrip("0") R.today_datetime["year"] = int(year) R.today_datetime["month"] = int(month) R.today_datetime["day"] = int(day) try: if len(rougeOB_task_data[str(month)]["last_finish"]) > 4: # 防一手格式错误 rougeOB_task_data[str(month)]["last_finish"] = rougeOB_task_data[str(month)]["last_finish"][0:4] except: pass if int(rougeOB_task_data[str(month)]["last_finish"]) < int(year): rougeOB_task_data[str(month)]["process"] = 0 rougeOB_task_data[str(month)]["last_finish"] = year rougeOB_task_data[str(month)]["rewarded"] = False if rougeOB_task_data["today"]["last_finish"] != year + "-" + month + "-" + day: rougeOB_task_data["today"]["process"] = 0 rougeOB_task_data["today"]["last_finish"] = year + "-" + month + "-" + day rougeOB_task_data["today"]["rewarded"] = False save_encrypt_single_rouge_file(rougeOB_task_data, "rougeOB_task") # 第一次打开 if not os.path.exists(rouge_file_path): # 若参与过第一轮beta测试 if os.path.exists(old_file_path): # 备份旧文件 old_json = load_json(old_file_path) rougeOB_data = {"Fox": {"exp": old_json["Fox"]["exp"], "lv": old_json["Fox"]["lv"]}, "Boboli": {"exp": old_json["Boboli"]["exp"], "lv": old_json["Boboli"]["exp"]}, "Naruto_old": {"exp": 0, "lv": 1}, "Asha": {"exp": old_json["Naruto_old"]["exp"], "lv": old_json["Naruto_old"]["exp"]}, "Maria": {"exp": 0, "lv": 1}, "Surprise": {"exp": 0, "lv": 1}} print("等级数据继承成功") else: rougeOB_data = { "Fox": {"exp": 0, "lv": 1}, "Boboli": {"exp": 0, "lv": 1}, "Naruto_old": {"exp": 0, "lv": 1}, "Asha": {"exp": 0, "lv": 1}, "Maria": {"exp": 0, "lv": 1}, "Surprise": {"exp": 0, "lv": 1} } save_encrypt_single_rouge_file(rougeOB_data, "rougeOB") # 正常打开 else: rougeOB_data = load_rouge_data(rouge_file_path) # ========================================================================================= util.load_online_config() if G.UID == "" and G.USERNAME == "": # username = input("请输入昵称: ").strip() # password = input("请输入密码: ").strip() util.register() new_info = rougeOB_data new_info["record"] = "null" result = util.update_profile(G.UID, new_info, G.PASSWORD) print(result.get('message', '未知错误')) is_online = util.try_login() if is_online: rougeOB_data = util.get_online_data() # ========================================================================================= check_rouge_ob_data(rougeOB_data) print(rougeOB_data) for hero in ["Fox", "Boboli", "Naruto_old", "Asha", "Maria"]: rougeOB_data[hero]["lv"] = R.current_lv(rougeOB_data[hero]["exp"]) self.Fox_info = "小倩: 等级" + str(rougeOB_data["Fox"]["lv"]) + ", 升级还需经验:" + current_lv( rougeOB_data["Fox"]["exp"]) + "\n技能: 自身血量减少1则糖泡伤害增加" + str(R.FoxSkill(rougeOB_data["Fox"]["lv"])) self.Boboli_info = "波波丽: 等级" + str(rougeOB_data["Boboli"]["lv"]) + ", 升级还需经验:" + current_lv( rougeOB_data["Boboli"]["exp"]) + "\n技能: 每次攻击额外造成" + str( int(R.BoboliSkill(rougeOB_data["Boboli"]["lv"]) * 100)) + "%真实伤害" self.Naruto_old_info = "火影: 等级" + str(rougeOB_data["Naruto_old"]["lv"]) + ", 升级还需经验:" + current_lv( rougeOB_data["Naruto_old"]["exp"]) + "\n技能: 首次攻击每只怪物时攻击力变为" + str( int(R.Naruto_oldSkill(rougeOB_data["Naruto_old"]["lv"]) * 100)) + "%" self.Asha_info = "阿莎: 等级" + str(rougeOB_data["Asha"]["lv"]) + ", 升级还需经验:" + current_lv( rougeOB_data["Asha"]["exp"]) + "\n技能: 每次糖泡造成伤害恢复血量" + str( R.AshaSkill(rougeOB_data["Asha"]["lv"]) * 100) + "%" self.Maria_info = "玛莉亚: 等级" + str(rougeOB_data["Maria"]["lv"]) + ", 升级还需经验:" + current_lv( rougeOB_data["Maria"]["exp"]) + "\n技能: 每次造成伤害降低怪物近身" + str( R.MariaSkill(rougeOB_data["Maria"]["lv"]) * 100) + "%(最高50%)与" + str( R.MariaSkill2(rougeOB_data["Maria"]["lv"])) + "防御" DM.init_achievement() rougeOB_achievements = load_rouge_data(rouge_achivements_file_path) print(rougeOB_achievements) max_level = 0 max_level_hero = "Fox" max_diff = "Easy" max_diff_num = 1 self.hero_dic = {"Fox": "小倩", "Boboli": "波波丽", "Naruto_old": "火影", "Asha": "阿莎", "Maria": "玛莉亚", "Surprise": "???"} self.diff_dic = {"Easy": "简单", "Normal": "困难", "Hell": "炼狱", "Hell+": "炼狱+"} diff_num = {"Easy": 1, "Normal": 2, "Hell": 3, "Hell+": 4} diff_status = {"Easy": 0, "Normal": 0, "Hell": 0, "Hell+": 0} max_level = rougeOB_achievements["Highest"]["level"] max_level_hero = rougeOB_achievements["Highest"]["hero"] max_diff = rougeOB_achievements["Highest"]["diff"] max_diff_num = diff_num[max_diff] if max_level == 20: diff_status[max_diff] = 2 if max_level > 0: 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]}" else: self.record_text = "暂无挑战记录" if max_diff == "Hell+": R.pass_status["Easy"] = 1 R.pass_status["Normal"] = 1 R.pass_status["Hell"] = 1 if max_level >= 15: R.pass_status["Hell+"] = 1 elif max_diff == "Hell": R.pass_status["Easy"] = 1 R.pass_status["Normal"] = 1 # R.cursor_skin = "fire_cursor_kubi" if max_level >= 15: R.pass_status["Hell"] = 1 # R.cursor_skin = "fire_cursor_gold_kubi" elif max_diff == "Normal": R.pass_status["Easy"] = 1 # R.cursor_skin = "fire_cursor2" if max_level >= 15: R.pass_status["Normal"] = 1 # R.cursor_skin = "fire_cursor_kubi" else: if max_level >= 15: R.pass_status["Easy"] = 1 # R.cursor_skin = "fire_cursor2" for dif in ["Easy", "Normal", "Hell", "Hell+"]: if diff_status[dif] == 2: R.pass_status[dif] = 2 def _create_buttons(self): # 主界面按钮 self.buttons.clear() # "进入游戏" # self.buttons.append(PygameButton(self.screen, "进入游戏", 0.5, 0.29, 32, "#e1bd48", action=self._start_game, is_bold=True)) self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.5, 0.3, "res/ui/button/start.png", "res/ui/button/start_press.png", action=self._start_game, anchor='center')) # "继续游戏" if os.path.exists(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")): self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.5, 0.44, "res/ui/button/continue.png", "res/ui/button/continue_press.png", action=lambda: self._continue_game(), anchor='center')) # 任务系统 self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.16, 0.16, "res/ui/button/task.png", "res/ui/button/task_press.png", action=self._open_task, anchor='center')) # 陈列馆 self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.16, 0.32, "res/ui/button/memory.png", "res/ui/button/memory_press.png", action=self._open_setting, anchor='center')) # 难度选择 last_diff = {"Easy": "Easy", "Normal": "Easy", "Hell": "Normal", "Hell+": "Hell"} for diff, rel in [("Easy", 0.1), ("Normal", 0.18), ("Hell", 0.26), ("Hell+", 0.34)]: if diff == R.difficulty: text = f"★ 当前难度: {self.diff_dic[diff]}" color = "#c7a44f" self.buttons.append(PygameButton(self.screen, text, 0.75, rel, 13, color, anchor="topleft", is_bold=True, fix_shape=(120,15), bg_alpha=191)) else: enabled = R.pass_status.get(last_diff[diff], 0) > 0 if diff == "Easy": text = f"● 选择{self.diff_dic[diff]}难度" color = "#99be7f" action = lambda d=diff: self._choose_diff(d) 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)) else: text = f"● 选择{self.diff_dic[diff]}难度" if enabled else f"○ {self.diff_dic[diff]}难度(未解锁)" color = "#99be7f" if enabled else "#55516d" if enabled: action = lambda d=diff: self._choose_diff(d) 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)) else: 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)) # ================================= 英雄选择 ================================= heroes = ["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Surprise"] x_position = 0.1 y_positions = [0.64, 0.70, 0.76, 0.82, 0.88, 0.49] for hero, y in zip(heroes, y_positions): if not self.is_random and hero == R.rouge_hero: text = f"★ 使用{self.hero_dic[hero]}" 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)) else: text = f"● 选择{self.hero_dic[hero]}" 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)) # 随机开局 if self.is_random: 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)) else: 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)) # 英雄信息提示 infos = [getattr(self, attr) for attr in ['Fox_info', 'Boboli_info', 'Naruto_old_info', 'Asha_info', 'Maria_info']] base_heroes = ["Fox", "Boboli", "Naruto_old", "Asha", "Maria"] if not self.is_random: for hero, info, y in zip(base_heroes, infos, y_positions): if hero == R.rouge_hero: self.buttons.append(PygameButton(self.screen, info, 0.32, y-0.03, 14, "#d7b8da", fg_color=(0, 0, 0), anchor="topleft", bg_alpha=127)) # ========================================================================== # 最高记录 record = getattr(self, 'record_text', "暂无挑战记录") self.buttons.append(PygameButton(self.screen, record, 0.5, 0.56, 14, "#7E354D", fg_color=(255, 255, 255), bg_alpha=191)) def refresh(self): """ 外部接口 """ self._create_buttons() def open_setting(self): self._open_setting() # 各个按钮动作方法 def _start_game(self): rougeGen.main_func() game = Control( screen=self.screen, is_continue=False ) game.update() def _continue_game(self): self.buttons.clear() last = load_rouge_data(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")) modification_time = os.path.getmtime(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")) readable_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(modification_time)) lvl = ((last["current_level"] + 4) // 2 - 1) // 5 + 1 stage = ((last["current_level"] + 4) // 2 - 1) % 5 + 1 text_c = f"\n继续游戏 (关卡: {lvl}-{stage}) \n (难度: {self.diff_dic[last['difficulty']]}; 英雄: {self.hero_dic[last['rouge_hero']]})\n{readable_time}" self.buttons.append( PygameButton(self.screen, text_c, 0.5, 0.4, 18, "#2a2a2a", fg_color=(215,220,217), action=lambda: self._continue_to_start(last), anchor="center", is_bold=True, fix_shape=(240,160), bg_alpha=159, frosted_glass=True, blur_radius=8, glass_alpha=8, background=self) ) self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.66, 0.72, "res/ui/button/return.png", "res/ui/button/return_press.png", action=self._create_buttons, anchor='center')) def _continue_to_start(self, last): self.read_continue_data(last) game = rogue_control.Control( screen=self.screen, is_continue=True ) game.update() def _open_task(self): self.buttons.clear() from game.ui.menu.task_menu import TaskPage page = TaskPage() page.draw() del page def _open_setting(self): self.buttons.clear() # try: # print("启动 Setting...") # from rougesetting import setting # t = threading.Thread(target=setting, daemon=True) # t.start() # except Exception as e: # print("启动 Setting 时出错:", e) from game.ui.menu.skin_menu import SkinPage page = SkinPage() page.draw() del page def _choose_diff(self, diff): R.difficulty = diff with open("config.json", "r", encoding="utf-8") as json_file: mapsetdata = json.load(json_file) mapsetdata["map_set"] = "rogueMapSet" mapsetdata["rogue_difficulty"] = diff with open("config.json", "w", encoding="utf-8") as json_file: json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False) self._create_buttons() def _choose_hero(self, hero): if hero == "Random": hero = random.choice(["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Surprise"]) self.is_random = True else: self.is_random = False R.rouge_hero = hero self.current_hero = hero with open("config.json", "r", encoding="utf-8") as json_file: mapsetdata = json.load(json_file) mapsetdata["map_set"] = "rogueMapSet" mapsetdata["your_hero"] = hero with open("config.json", "w", encoding="utf-8") as json_file: json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False) self._create_buttons() def run(self): clock = pygame.time.Clock() spawn_timer = 0 while True: dt = clock.tick(120) spawn_timer += dt # ================================= 处理鼠标事件 ===================================== for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() for btn in self.buttons: btn.handle_event(event) if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: # 看看有没有按钮自己处理了这次点击 if not any(btn.bg_rect.collidepoint(event.pos) for btn in self.buttons): sound_player.play("uiFail") else: sound_player.play("uiLeave") # =================================================================================== # 随机生成新粒子: 每200ms生成一个 if spawn_timer > 200: spawn_timer = 0 x = random.randint(0, self.screen.get_width()) y = self.screen.get_height() + 10 self.particles.append(Particle(x, y)) # 更新和过滤粒子 new_particles = [] for p in self.particles: p.update() if p.is_alive(): new_particles.append(p) self.particles = new_particles # ===================================== 绘制画面 ====================================== # 绘制背景 if self.bg_image: self.screen.blit(self.bg_image, (0, 0)) else: self.screen.fill((60, 90, 60)) # 绘制粒子 for p in self.particles: p.draw(self.screen) # 绘制按钮 for btn in self.buttons: btn.draw() pygame.display.flip() # 读取上次存档 def read_continue_data(self, last_data): R.continuing_game = True self.current_hero = last_data["rouge_hero"] with open("config.json", "r", encoding="utf-8") as json_file: mapsetdata = json.load(json_file) mapsetdata["map_set"] = "rogueMapSet" mapsetdata["your_hero"] = last_data["rouge_hero"] with open("config.json", "w", encoding="utf-8") as json_file: json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False) # =============================================================================== G.CURRENT_LEVEL = last_data["current_level"] R.map_json_dic = last_data["map_json_dic"] R.central_mapset = last_data["central_mapset"] R.difficulty = last_data["difficulty"] R.today_datetime = last_data["today_datetime"] R.task_RougeTreasureDestinyElite = last_data["task_RougeTreasureDestinyElite"] R.task_MineCFireDragonBoss = last_data["task_MineCFireDragonBoss"] R.task_RougeTreasureDestinyWizard = last_data["task_RougeTreasureDestinyWizard"] R.task_combat = last_data["task_combat"] R.task_revival = last_data["task_revival"] R.rouge_data = last_data["rouge_data"] R.rouge_hero = last_data["rouge_hero"] R.rouge_lv = last_data["rouge_lv"] R.rouge_exp = last_data["rouge_exp"] R.game_exp = last_data["game_exp"] R.rouge_story = last_data["rouge_story"] R.rouge_theme_1 = last_data["rouge_theme_1"] R.rouge_theme_2 = last_data["rouge_theme_2"] R.rouge_theme_3 = last_data["rouge_theme_3"] R.rouge_theme_4 = last_data["rouge_theme_4"] R.rouge_destiny = last_data["rouge_destiny"] R.coin = last_data["coin"] R.general_mon_dic = last_data["general_mon_dic"] R.story_eden = last_data["story_eden"] R.story_destiny = last_data["story_destiny"] R.current_standard_HP = last_data["current_standard_HP"] R.current_standard_damage = last_data["current_standard_damage"] R.current_standard_speed = last_data["current_standard_speed"] R.current_standard_defense = last_data["current_standard_defense"] R.current_standard_bomb = last_data["current_standard_bomb"] R.se_district = last_data["se_district"] R.battle_district = last_data["battle_district"] R.monster_defense_delta = last_data["monster_defense_delta"] R.monster_HP_rate = last_data["monster_HP_rate"] R.player_bomb_self_damage_reduce_rate = last_data["player_bomb_self_damage_reduce_rate"] R.slow_immune = last_data["slow_immune"] R.reverse_immune = last_data["reverse_immune"] R.root_immune = last_data["root_immune"] R.stun_immune = last_data["stun_immune"] R.random_dmg = last_data["random_dmg"] R.show_cursor = last_data["show_cursor"] R.last_item = last_data["items"] if os.path.exists(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")): os.remove(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")) print("已读取,清除数据!!!!!!!!!!!!!") else: print("???") def show_prompt(): """显示提示框,询问用户如何操作""" import tkinter as tk from tkinter import messagebox def close_existing(): root.destroy() sys.exit() root = tk.Tk() root.withdraw() # 隐藏主窗口 if messagebox.askyesno("进程已打开", "已有一个游戏进程正在运行。请关闭后再运行!"): close_existing() # 获取所有窗口句柄 def get_all_windows(): windows = [] def enum_windows_proc(hwnd, _): if win32gui.IsWindowVisible(hwnd): window_text = win32gui.GetWindowText(hwnd) if window_text: windows.append(window_text) return True win32gui.EnumWindows(enum_windows_proc, None) return windows # 检测窗口是否存在 def check_window_exists(): windows = get_all_windows() # print(windows) for window in windows: if "QQTRogue" in window and "永恒" in window and "100の雨女" in window and "756422783" in window and "擅自售卖皆属剽窃" in window: return True return False class Launcher: def __init__(self): pygame.init() self.screen = pygame.display.set_mode(W.WINDOW_SIZE) pygame.display.set_caption(W.WINDOW_CAPTION) self.cfg_json = {} self.music_volume = 0.7 self.display_flags = 0 self.init_config() self.init_window() # 预加载资源 # self.preload_resources() # 启动菜单 music_loader.play("rogue_menu.mp3", self.music_volume) self.menu = Menu(self.screen, bg_image_path="res/ui/game/rogue_menu.png") self.menu.run() def init_config(self): try: with open("config.json", encoding="utf-8") as f: self.cfg_json = json.load(f) except json.JSONDecodeError: with open("config.json", encoding="utf-8_sig") as f: self.cfg_json = json.load(f) self.music_volume = self.cfg_json["music_volume"] if not self.cfg_json["frame_screen"]: self.display_flags = pygame.NOFRAME if self.cfg_json["full_screen"]: self.display_flags = pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF try: if self.cfg_json["v_sync"] and self.cfg_json["frame_screen"] and not self.cfg_json["full_screen"]: self.display_flags = pygame.HWSURFACE | pygame.DOUBLEBUF # self.display_flags = pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.OPENGL elif self.cfg_json["v_sync"] and not self.cfg_json["frame_screen"]: self.display_flags |= pygame.HWSURFACE | pygame.DOUBLEBUF elif self.cfg_json["v_sync"] and self.cfg_json["full_screen"]: self.display_flags = pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF except Exception as e: print(e) def init_window(self): self.screen = pygame.display.set_mode(W.WINDOW_SIZE, flags=self.display_flags) pygame.display.set_icon(pygame.image.load("res/img/ui/icon.png").convert_alpha()) for i in range(10): file_name = "itemNum_0_" + str(i) + ".png" img = pygame.image.load("res/img/ui/number/" + file_name).convert_alpha() G.NUMBER_IMG.append(img) def preload_resources(self): with concurrent.futures.ThreadPoolExecutor() as executor: executor.submit(Control.preload) if __name__ == "__main__": # # 定义日志文件路径 # # log_file_path = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "program.log") # log_file_path = os.path.join(os.getcwd(), "program.log") # # 打开日志文件并重定向 stdout # log_file = open(log_file_path, 'a', encoding='utf-8') # 'a' 是追加模式 # # 重定向 sys.stdout(print 函数输出) # sys.stdout = log_file # # 重定向 sys.stderr(报错信息) # sys.stderr = log_file print("=========== start ==============") if check_window_exists(): show_prompt() Launcher()