微信跳一跳輔助python代碼實(shí)現(xiàn)
微信跳一跳輔助的python具體實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
這是一個(gè) 2.5D 插畫風(fēng)格的益智游戲,玩家可以通過按壓屏幕時(shí)間的長(zhǎng)短來(lái)控制這個(gè)「小人」跳躍的距離??赡軇傞_始上手的時(shí)候,因?yàn)闀r(shí)間距離之間的關(guān)系把握不恰當(dāng),只能跳出幾個(gè)就掉到了臺(tái)子下面。
玩法類似于《flappy bird》
下載github的一個(gè)程序,但是在windows10下不能運(yùn)行,原因是windows10下沒有copy命令了,修改為Python自帶的復(fù)制方法,即可完成。今天運(yùn)行好像一開始不能正確跳第一次,人工輔助后,后續(xù)的跳的很好。
部分代碼:
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 = 按鍵時(shí)長(zhǎng) # 此數(shù)據(jù)是 iPhoneX 的推薦系數(shù),可根據(jù)手機(jī)型號(hào)進(jìn)行調(diào)整 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. 將手機(jī)點(diǎn)擊到《跳一跳》小程序界面;
2. 用Adb 工具獲取當(dāng)前手機(jī)截圖,并用adb將截圖pull上來(lái)
```shell
adb shell screencap -p /sdcard/1.png
adb pull /sdcard/1.png .
```
3. 用matplot顯示截圖;
4. 用鼠標(biāo)點(diǎn)擊起始點(diǎn)和目標(biāo)位置,計(jì)算像素距離;
5. 根據(jù)像素距離,計(jì)算按壓時(shí)間;
6. 用Adb工具點(diǎn)擊屏幕蓄力一跳;
代碼較多,直接為大家分享源碼下載鏈接,很詳細(xì):微信跳一跳輔助python代碼實(shí)現(xiàn)
更多內(nèi)容大家可以參考專題《微信跳一跳》進(jìn)行學(xué)習(xí)。
相關(guān)文章學(xué)習(xí)推薦:
python基于TensorFlow實(shí)現(xiàn)微信跳一跳的AI
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python實(shí)現(xiàn)一個(gè)搖骰子小游戲
大家好,本篇文章主要講的是python實(shí)現(xiàn)一個(gè)搖骰子小游戲,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下2022-01-01Pandas索引排序 df.sort_index()的實(shí)現(xiàn)
本文主要介紹了Pandas索引排序 df.sort_index()的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07Django應(yīng)用程序入口WSGIHandler源碼解析
這篇文章主要介紹了Django應(yīng)用程序入口WSGIHandler源碼解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08Python結(jié)合Selenium簡(jiǎn)單實(shí)現(xiàn)Web自動(dòng)化測(cè)試
這篇文章是入門級(jí)別的應(yīng)用Python + Selenium進(jìn)行自動(dòng)化測(cè)試,包括環(huán)境搭建及簡(jiǎn)單的實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09使用pytorch時(shí)所遇到的一些問題總結(jié)
這篇文章主要介紹了使用pytorch時(shí)所遇到的一些問題總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05Python數(shù)據(jù)可視化之繪制柱狀圖和條形圖
今天帶大家學(xué)習(xí)怎么利用Python繪制柱狀圖,條形圖,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們很有幫助,需要的朋友可以參考下2021-05-05python GUI庫(kù)圖形界面開發(fā)之PyQt5輸入對(duì)話框QInputDialog詳細(xì)使用方法與實(shí)例
這篇文章主要介紹了python GUI庫(kù)圖形界面開發(fā)之PyQt5輸入對(duì)話框QInputDialog詳細(xì)使用方法與實(shí)例,需要的朋友可以參考下2020-02-02Python控制臺(tái)實(shí)現(xiàn)交互式環(huán)境執(zhí)行
這篇文章主要介紹了Python程序如何在交互式環(huán)境中執(zhí)行,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06