微信跳一跳辅助python代码实现
作者:lijiao 时间:2023-03-26 15:25:50
微信跳一跳辅助的python具体实现代码,供大家参考,具体内容如下
这是一个 2.5D 插画风格的益智游戏,玩家可以通过按压屏幕时间的长短来控制这个「小人」跳跃的距离。可能刚开始上手的时候,因为时间距离之间的关系把握不恰当,只能跳出几个就掉到了台子下面。
玩法类似于《flappy bird》
下载github的一个程序,但是在windows10下不能运行,原因是windows10下没有copy命令了,修改为Python自带的复制方法,即可完成。今天运行好像一开始不能正确跳第一次,人工辅助后,后续的跳的很好。
部分代码:
wechat_jump_iOS_py3.py
import wda
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from PIL import Image
import math
import time
import os
# 截图距离 * time_coefficient = 按键时长
# 此数据是 iPhoneX 的推荐系数,可根据手机型号进行调整
time_coefficient = 0.00125
c = wda.Client()
s = c.session()
def pull_screenshot():
c.screenshot('1.png')
def jump(distance):
press_time = distance * time_coefficient
press_time = press_time
print(press_time)
s.tap_hold(200,200,press_time)
fig = plt.figure()
index = 0
cor = [0, 0]
pull_screenshot()
img = np.array(Image.open('1.png'))
update = True
click_count = 0
cor = []
def update_data():
return np.array(Image.open('1.png'))
im = plt.imshow(img, animated=True)
def updatefig(*args):
global update
if update:
time.sleep(1)
pull_screenshot()
im.set_array(update_data())
update = False
return im,
def onClick(event):
global update
global ix, iy
global click_count
global cor
# next screenshot
ix, iy = event.xdata, event.ydata
coords = []
coords.append((ix, iy))
print('now = ', coords)
cor.append(coords)
click_count += 1
if click_count > 1:
click_count = 0
cor1 = cor.pop()
cor2 = cor.pop()
distance = (cor1[0][0] - cor2[0][0])**2 + (cor1[0][1] - cor2[0][1])**2
distance = distance ** 0.5
print('distance = ', distance)
jump(distance)
update = True
fig.canvas.mpl_connect('button_press_event', onClick)
ani = animation.FuncAnimation(fig, updatefig, interval=50, blit=True)
plt.show()
wechat_jump_py3.py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from PIL import Image
import math
import time
import os
def pull_screenshot():
os.system('adb shell screencap -p /sdcard/1.png')
os.system('adb pull /sdcard/1.png .')
def jump(distance):
press_time = distance * 1.35
press_time = int(press_time)
cmd = 'adb shell input swipe 320 410 320 410 ' + str(press_time)
print(cmd)
os.system(cmd)
fig = plt.figure()
index = 0
cor = [0, 0]
pull_screenshot()
img = np.array(Image.open('1.png'))
update = True
click_count = 0
cor = []
def update_data():
return np.array(Image.open('1.png'))
im = plt.imshow(img, animated=True)
def updatefig(*args):
global update
if update:
time.sleep(1.5)
pull_screenshot()
im.set_array(update_data())
update = False
return im,
def onClick(event):
global update
global ix, iy
global click_count
global cor
# next screenshot
ix, iy = event.xdata, event.ydata
coords = []
coords.append((ix, iy))
print('now = ', coords)
cor.append(coords)
click_count += 1
if click_count > 1:
click_count = 0
cor1 = cor.pop()
cor2 = cor.pop()
distance = (cor1[0][0] - cor2[0][0])**2 + (cor1[0][1] - cor2[0][1])**2
distance = distance ** 0.5
print('distance = ', distance)
jump(distance)
update = True
fig.canvas.mpl_connect('button_press_event', onClick)
ani = animation.FuncAnimation(fig, updatefig, interval=50, blit=True)
plt.show()
原理说明
1. 将手机点击到《跳一跳》小程序界面;
2. 用Adb 工具获取当前手机截图,并用adb将截图pull上来
```shell
adb shell screencap -p /sdcard/1.png
adb pull /sdcard/1.png .
```
3. 用matplot显示截图;
4. 用鼠标点击起始点和目标位置,计算像素距离;
5. 根据像素距离,计算按压时间;
6. 用Adb工具点击屏幕蓄力一跳;
代码较多,直接为大家分享源码下载链接,很详细:微信跳一跳辅助python代码实现
更多内容大家可以参考专题《微信跳一跳》进行学习。
相关文章学习推荐:
跳一跳小游戏python脚本
python基于TensorFlow实现微信跳一跳的AI
标签:python,微信,跳一跳


猜你喜欢
细数nn.BCELoss与nn.CrossEntropyLoss的区别
2021-04-16 16:29:28

合理关闭XHTML标签
2008-06-25 13:20:00
js中的window.open返回object的错误的解决方法
2024-04-17 09:52:27
ASP 循环导入导出数据处理 不使用缓存
2010-07-02 12:31:00
golang 执行命令行的实现
2024-04-28 09:14:40
python爬虫入门教程之点点美女图片爬虫代码分享
2021-01-14 21:45:07
解读HTML:大厦的基石
2008-12-01 12:57:00
Go语言判断文件或文件夹是否存在的方法
2024-05-09 14:50:55
使用 prometheus python 库编写自定义指标的方法(完整代码)
2021-03-03 06:03:58
asp版FCKEditor编辑器的用法
2008-07-05 12:15:00
详解Python爬取并下载《电影天堂》3千多部电影
2023-07-07 23:48:24

JavaScript es6中var、let以及const三者区别案例详解
2024-05-09 15:06:26
Pytorch中使用TensorBoard详情
2023-07-11 01:14:56

手机使用python操作图片文件(pydroid3)过程详解
2021-06-19 13:45:39

Python网络爬虫之获取网络数据
2022-10-09 12:35:54
利用Pandas索引和选取数据方法详解
2023-04-30 23:30:07

分享15 超级好用得 Python 实用技巧
2023-03-01 06:42:09
提高MySQL数据库查询效率的三个实用技巧
2008-12-03 16:40:00
python 读取txt中每行数据,并且保存到excel中的实例
2022-06-14 02:28:09
python 密码加密与解密的实现
2023-07-31 04:32:38
