You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Curriculum_Design/simple_minesweeper_test.py

58 lines
1.7 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
简化版扫雷游戏测试脚本
用于快速测试扫雷游戏模块是否能正常运行
"""
import sys
import os
# 添加项目根目录到Python路径
project_root = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, project_root)
# 设置Qt环境变量
def setup_qt_env():
"""设置基本的Qt环境变量"""
venv_plugins = os.path.join(project_root, '.venv', 'Lib', 'site-packages', 'PyQt5', 'Qt5', 'plugins')
if os.path.exists(venv_plugins):
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.join(venv_plugins, 'platforms')
print(f"✅ Qt平台插件路径已设置: {os.environ['QT_QPA_PLATFORM_PLUGIN_PATH']}")
return True
else:
print("❌ 未找到Qt平台插件路径")
return False
# 尝试设置Qt环境
if not setup_qt_env():
print("警告Qt环境设置失败游戏可能无法正常显示")
try:
from PyQt5.QtWidgets import QApplication, QMainWindow
from src.ui.minesweeper_game import MinesweeperWindow
def main():
app = QApplication(sys.argv)
# 创建并显示扫雷游戏窗口
window = MinesweeperWindow()
window.show()
print("🎮 扫雷游戏窗口已显示")
print(" 请检查是否有游戏窗口弹出")
print(" 如果没有窗口弹出请关闭此窗口并检查Qt环境配置")
sys.exit(app.exec_())
if __name__ == '__main__':
main()
except ImportError as e:
print(f"❌ 导入错误: {e}")
print("请确保已正确安装PyQt5")
except Exception as e:
print(f"❌ 运行错误: {e}")
import traceback
traceback.print_exc()