A simple tutorial on Python making turn-based hands-on tour (top)

Source: Internet
Author: User

introduced:

Every time you play a turn-based game, the repeated daily tasks make people patience

When asked, we want to be able to automatically brush the road, play fantasy hope can automatically do the division door, catch ghosts and so on

Description:

The plug can only simulate mouse keyboard operation, and can not modify the game data

The python2.7 I use here

Development tools are Pycharm

Pre-Knowledge Preparation:

First download Autopy package, I pycharm here can directly import autopy package

or install with PIP: Pip install autopy

Mouse Movement

Copy the following code, run

#coding =utf-8import time import Autopy#quick moveautopy.mouse.move (1,1) # Smooth Move#autopy.mouse.smooth_move (1370,)

You will notice that the mouse moves to the coordinates (1920*1080) instantly, my computer is the same, the bottom right corner of the coordinates is (1920,1080).

Change the move to Smooth_move, and you'll notice that the mouse moves slowly to the specified coordinates

Explanation of official documents:

Autopy.mouse.move (X:float, Y:float)

Moves the mouse to the given (x, y) coordinate.

Exceptions:

ValueError is thrown if the point is out of index.

Autopy.mouse.smooth_move (X:float, Y:float)

Smoothly moves the mouse to the given (x, y) coordinate on a straight line.

Exceptions:

ValueError is thrown if the point is out of index.

Coordinates exceeding resolution will report an exception

Mouse click

Run the code and find that the current location has a click action

#coding =utf-8Import Autopyautopy.mouse.click () # Click

keyboard Operation

The following are some common key-value codes and the corresponding keys:

Keys for alphanumeric keypad key function keys other keys
Key code key keys key code keys key code
A 0 F1 Backspace 8
B 1 F2 113 Tab 9
C 2 98 F3 Clear 12
D-3 F4-13
E 4 F5-Shift 16
F 5 101 F6 117 Control 17
G 6 102 F7 118 Alt 18
H 7 103 F8 119 caps Lock 20
I 8 104 F9 27 ESC
J 9 F10 121 Spacebar 32
K * 106 F11 122 Page up 33
L + 107 F12 123 Page down 34
M + Enter 108 End 35
N 78-109 Home 36
O 79. 37 left Arrow
P 80/111 up Arrow 38
Q Bayi RightArrow 39
R DownArrow 40
S-45 Insert
T-Delete 46
U-Help 47
V NumLock 144
W 87
X 88
Y 89
Z 90
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57

Copy code, run, need WIN32API package here

Call Win32API's Keybd_event method, use to release the key

#coding =utf-8Import timeimport Win32API win32api.keybd_event ( -,0,0,0) #alt键位码是18win32api. keybd_event (9,0,0,0) #tab键位码是9time. Sleep (0.5) win32api.keybd_event ( -,0,0,0) #enter键位码是13 win32api.keybd_event ( -,0, Win32con. Keyeventf_keyup,0) #释放按键win32api. keybd_event (9,0, Win32con. Keyeventf_keyup,0) win32api.keybd_event ( -,0, Win32con. Keyeventf_keyup,0) Time.sleep (2)

As you can see, the Switch window is completed, which is equivalent to pressing ALT + TAB and then enter

Start making plug-ins:

Here is an example of asking for a hand tour (turn-based hand-travel is similar)

Need night God simulator and install on simulator ask

I tried the blue stack and Mumu simulator, I use Autopy to move the mouse to the simulator when the mouse disappears, can not complete the subsequent automatic operation, later Baidu

Say that some simulators are not controlled by the win window. No matter how much, let's start with the night God simulator!

Enter the game and open "events"

We use "arena" activities to illustrate

We're going to use a tool here, and I'm using Picpick.

Personal user free, I mainly use it to measure coordinates

Record the coordinates of the arena (1358,504)

Record the coordinates of the Arena button (1332,650)

Making a turn-based script first needs to be familiar with the task flow

Then click on the arena, go through this task flow, record the coordinates of the button in turn

Arena quests can be done five times a day, we cycle through the steps five times

Combat time we need to time ourselves, different gate, local tyrants, or civilian players.

I am a civilian player, probably time-consuming 60s, click on the challenge to let the code delay 60s before continuing execution

Copy code, run

#coding =utf-8import autopyimport timeimport win32apiimport win32con# Arena win32api.keybd_event ( -,0,0,0) #alt键位码是18win32api. keybd_event (9,0,0,0) #tab键位码是9time. Sleep (0.5) win32api.keybd_event ( -,0,0,0) #enter键位码是13 win32api.keybd_event ( -,0, Win32con. Keyeventf_keyup,0) #释放按键win32api. keybd_event (9,0, Win32con. Keyeventf_keyup,0) win32api.keybd_event ( -,0, Win32con. Keyeventf_keyup,0) Time.sleep (2) def mousemove_click (x, y): Autopy.mouse.smooth_move (Autopy.mouse.click) Mousemove_click (771,203) # Active coordinate Mousemove_click (1358,504) # Arena"go to"the coordinate time.sleep ( -) #从天墉城城中心/other maps go to the athletic messenger to spend 20s Mousemove_click (1334,650# The coordinates #挑战完毕会出现对话窗口 of the arena in the Athletics Messenger dialog box forIinchRange1,6,1): Mousemove_click (664,706) #挑战试炼童子 Mousemove_click (1082,578) #确认 Mousemove_click (1530,794) # Battle Auto Time.sleep ( -) #挑战试炼童子预计60s

The effect is as follows:

The next episode will show you how to implement the Captain mode brush path (auto-teaming, auto-run ring Task)

A simple tutorial on Python making turn-based hands-on tour (top)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.