Drawing on the code and ideas of some of the gods on the Internet, here to organize the idea of writing a click jump to play the small game of jump!
I. Overall thinking
The coordinates of where the piece is and the coordinates of the next move it will go to, and the distance between the two points is calculated from the two coordinates to make the jump.
II. Distributional ideas
1、According to the command to take a screenshot to get the initial map saved to the phone, and then uploaded to the local folder
2. Put the acquired screenshots into the newly created axes (matplotlib)
3, through the mouse click event to obtain the initial coordinates of the location as well as the focus coordinates, and calculate the straight line distance
4. Make a jump, clear the coordinates and update the screenshot after the jump is completed.
III. Relevant technologies or modules used
1、python3 foundation
2、numpy
3、matplotlib
4. os module in python
5. adb toolkit
IV. Codes
__author__ = 'Zhou Yanbing' import os import PIL,numpy import as plt from import FuncAnimation import time need_update = True # Get a screenshot of your phone def get_screen_image(): ('adb shell screencap -p /sdcard/') # Get a screenshot of your phone's current interface ('adb pull /sdcard/') # Download the current screenshot to the current folder on your computer return (('')) # Convert to array and return # Calculate the length of the string def jump_to_next(point1, point2): x1, y1 = point1; x2, y2 = point2 distance = ((x2-x1)**2 + (y2-y1)**2)**0.5 # Calculate the string length ('adb shell input swipe 320 410 320 410 {}'.format(int(distance*1))) # Press the left side of the horizontal and vertical Release the horizontal and vertical coordinates Press the time 2K has a screen bounce factor of 1 # Bind mouse click events def on_calck(event, coor=[]): # [(x,y),(x2,y2)] global need_update ((, )) # Get the x and y coordinate positions into the coor array if len(coor) == 2: jump_to_next((), ()) # Calculate the length and empty the array after getting two coordinates need_update = True def update_screen(frame): # Update the picture global need_update if need_update: (1) # Because jumping takes time so here you need to hibernate for 1s and then re-fetch the image axes_image.set_array(get_screen_image()) need_update = False return axes_image, # Return to the genesis figure = () # Create a blank picture object/create a canvas axes_image = (get_screen_image(), animated=True) # Put the fetched image on the axes .mpl_connect('button_press_event', on_calck) ani = FuncAnimation(figure, update_screen, interval=50, blit=True) # Instantiate FuncAnimation to update canvas image 50 for 50ms () # Display coordinate charts
Click here to get it:Jump Source Code
For more, you can refer to the topic"WeChat JumpUndertake a study.
This is the whole content of this article.