diff --git a/.gitignore b/.gitignore index 70700a2..95b6a95 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -./vscode \ No newline at end of file +/.vscode +/output +/temp_build +/build \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index 0449447..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "configurations": [ - { - "name": "Win32", - "includePath": [ - "${default}" - ], - "defines": [ - "_DEBUG", - "UNICODE", - "_UNICODE" - ], - "windowsSdkVersion": "10.0.22621.0", - "cStandard": "c17", - "cppStandard": "c++17", - "intelliSenseMode": "windows-msvc-x64", - "compilerPath": "C:/code/Env/mingw64/bin/g++.exe" - } - ], - "version": 4 -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 46713b4..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "files.associations": { - "Kconfig": "shellscript", - "*.vue": "vue", - "*.cjson": "jsonc", - "*.wxss": "css", - "*.wxs": "javascript", - "chrono": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "charconv": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "compare": "cpp", - "concepts": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "string": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "format": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "new": "cpp", - "numbers": "cpp", - "ostream": "cpp", - "semaphore": "cpp", - "span": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "stop_token": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "typeinfo": "cpp", - "variant": "cpp" - } -} \ No newline at end of file diff --git a/Build.bat b/Build.bat new file mode 100644 index 0000000..5249e09 --- /dev/null +++ b/Build.bat @@ -0,0 +1,45 @@ +@echo off +REM 设置字符编码为 UTF-8 +chcp 65001 +cls + +REM compile_WebServer.bat + +REM 设置变量 +set "SCRIPT_NAME=start.py" +set "EXE_NAME=zzz-snake.exe" +set "TEMP_DIR=temp_build" +set "OUTPUT_DIR=output" + +REM 创建临时目录和输出目录 +if not exist "%TEMP_DIR%" mkdir "%TEMP_DIR%" +if not exist "%OUTPUT_DIR%" mkdir "%OUTPUT_DIR%" + +REM 安装必要的 Python 包 +echo 正在安装必要的 Python 包... +pip install pyinstaller +pip install -r requirements.txt + +REM 复制 Python 脚本到临时目录 +copy "%SCRIPT_NAME%" "%TEMP_DIR%" + +REM 切换到临时目录 +cd "%TEMP_DIR%" + +REM 使用 PyInstaller 编译脚本 +echo 正在编译脚本... +pyinstaller -D --uac-admin --onefile --name "%EXE_NAME%" "%SCRIPT_NAME%" + +REM 将生成的 EXE 文件移动到输出目录 +move "dist\%EXE_NAME%" "..\%OUTPUT_DIR%" + +REM 切换回原始目录 +cd .. + +REM 清理临时文件 +rmdir /s /q "%TEMP_DIR%" + +echo 编译完成!executable 文件位于: %OUTPUT_DIR%\%EXE_NAME% + +REM 暂停以查看输出 +pause \ No newline at end of file diff --git a/README.md b/README.md index 6d2b3d6..eaf6c6a 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,36 @@ # 绝区零蛇对蛇全自动刷分脚本 -此Python脚本通过模拟键盘输入来自动控制蛇进行刷分。脚本会让蛇以原地转圈的方式移动并在失败后自动重新开始,从而实现全自动刷分(很难刷到千万分以上). - -## 安装方法 - -1. 安装库`pip install keyboard pyautogui` -2. 克隆存储库`git clone https://github.com/1492949083/ZenlessZoneZero-Snake.git` -4. 运行`python start.py` -5. 在蛇对蛇游戏中,按下 `F10` 键开始自动刷分(不用操控,脚本会自动将蛇移动到角落)。 -6. 按下 `F11` 键暂停刷分。 -7. Ctrl + C 退出 +通过模拟键盘输入来自动控制蛇进行刷分。让蛇以原地转圈的方式移动并在失败后自动重新开始,从而实现全自动刷分(很难刷到千万分以上)。 + +## 使用方法 + +### 使用打包好的 exe 文件 + +1. 下载打包好的 exe 文件。 +2. 从蛇对蛇失败界面[此处](doc/img/1.png)截图取名 `image.png` 和 exe 文件放一起![s](doc/img/2.png) +3. 双击运行 exe 文件。 +4. 在蛇对蛇游戏中,按下 `F10` 键开始自动刷分(脚本会自动将蛇移动到角落)。 +5. 按下 `F11` 键暂停刷分。 +6. 关闭窗口退出。 + +### 使用源代码 + +1. 安装所需库: + ```sh + pip install -r requirements.txt + ``` +2. 克隆存储库: + ```sh + git clone https://github.com/1492949083/ZenlessZoneZero-Snake.git + cd ZenlessZoneZero-Snake + ``` +3. 运行脚本: + ```sh + python start.py + ``` +4. 在蛇对蛇游戏中,按下 `F10` 键开始自动刷分(脚本会自动将蛇移动到角落)。 +5. 按下 `F11` 键暂停刷分。 +6. 按 `Ctrl + C` 退出。 ## 注意事项 @@ -18,7 +39,8 @@ ## 常见问题 -- 如果游戏失败后不会自动重新开始,请将游戏结束界面此处截图并替换/img/image.png文件。![image](doc/img/1.png) +- 如果游戏失败后不会自动重新开始,请将游戏结束界面截图并替换 `image.png` 文件。 + ![image](doc/img/1.png) ## 免责声明 diff --git a/doc/img/2.png b/doc/img/2.png new file mode 100644 index 0000000..65c665e Binary files /dev/null and b/doc/img/2.png differ diff --git a/img/image.png b/image.png similarity index 100% rename from img/image.png rename to image.png diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5bbf709 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +keyboard +pyautogui +opencv-python \ No newline at end of file diff --git a/start.py b/start.py index 8219223..68bdf5d 100644 --- a/start.py +++ b/start.py @@ -2,6 +2,7 @@ import time import threading import pyautogui as pyg +import os # 用于表示脚本是否应该继续运行 continue_running = False @@ -12,7 +13,6 @@ timer_lock = threading.Lock() rounds = 0 - # 去左上角 def go_to_top_left(): global continue_running @@ -89,29 +89,34 @@ def timer(): def click_over_img(): global rounds,continue_running height, width = pyg.size() - print(height, width) + # print(height, width) #左上角 left_top_x = int(width/3) left_top_y = int(height/3) #右下角 right_bottom_x = int(width - width/3) right_bottom_y = int(height - height/3) - print(left_top_x, left_top_y, right_bottom_x, right_bottom_y) + # print(left_top_x, left_top_y, right_bottom_x, right_bottom_y) while pag_running: - img = pyg.locateCenterOnScreen("./img/image.png", confidence=0.8, region=(left_top_x, left_top_y, right_bottom_x, right_bottom_y)) - if img != None: - continue_running = False - pyg.click(img) - time.sleep(1.5) - go_to_top_left() - rounds += 1 - elif rounds == 0: - # continue_running = True - go_to_top_left() - rounds = 1 + try: + img = pyg.locateCenterOnScreen("image.png", confidence=0.8, region=(left_top_x, left_top_y, right_bottom_x, right_bottom_y)) + if img != None: + continue_running = False + pyg.click(img) + time.sleep(1.5) + go_to_top_left() + rounds += 1 + elif rounds == 0: + # continue_running = True + go_to_top_left() + rounds = 1 + except pyg.ImageNotFoundException: + # print("图片未找到") + continue + finally: + time.sleep(1) - time.sleep(1) # 当 F10 键被按下时,调用 start_script 函数 keyboard.on_press_key("f10", start_script) @@ -130,5 +135,9 @@ def click_loop(): # 在一个新的线程中运行 click_loop 函数 threading.Thread(target=click_loop, daemon=True).start() +print("F10 键启动") +print("F11 键暂停") +print("Ctrl+C 键退出") + # 运行程序 keyboard.wait()