This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathandroid_jump.py
62 lines (48 loc) · 1.68 KB
/
android_jump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# coding: u8
from __future__ import print_function, unicode_literals
import itertools
import os.path as osp
import time
import traceback
import numpy
from libjump import Otsu, run_cmd, create_screenshot_directory
# directory where screenshot image will be saved in.
# if you use Windows, e.g 'c:/wechat_micro_jump_game_screenshot'
screenshot_directory = '/tmp/wechat_micro_jump_game_screenshot'
create_screenshot_directory(screenshot_directory)
jump_times = itertools.count(0)
while True:
try:
debug = False
if debug:
# your last failed image name
fn = '0.png'
fp = osp.join(screenshot_directory, fn)
else:
fn = str(next(jump_times)) + '.png'
fp = osp.join(screenshot_directory, fn)
run_cmd('adb shell screencap -p /sdcard/s.png')
run_cmd('adb pull /sdcard/s.png {}'.format(fp))
print(fp)
otsu = Otsu(fp, debug, 1.5)
holding = int(otsu.get_holding())
if debug:
raise KeyboardInterrupt
else:
# random tap position
# anti-wechat detect
rand_x = lambda: numpy.random.randint(0, otsu.w)
rand_y = lambda: numpy.random.randint(0, otsu.h * 3 / 4)
x1, y1 = rand_x(), rand_y()
x2, y2 = rand_x(), rand_y()
run_cmd('adb shell input swipe {0} {1} {2} {3} {4}'.format(
x1, y1, x2, y2, holding))
sleep_time = .7
time.sleep(sleep_time)
print('sleeping seconds', sleep_time)
print()
except KeyboardInterrupt:
raise KeyboardInterrupt
except:
traceback.print_exc()
time.sleep(2)