Python实现微信跳一跳

# 安装PyGame:pip install pygame
import pygame
import os
import time
import math


from pygame.locals import *
from sys import exit

img_qp = "a11111.png"


pygame.init()
screen = pygame.display.set_mode((360, 640), RESIZABLE, 32)

pygame.display.set_caption("跳一跳")

# 加载手机界面
os.system('adb shell screencap -p /sdcard/a11111.png')
os.system('adb pull /sdcard/a11111.png')
qp = pygame.image.load(img_qp).convert()
qp = pygame.transform.smoothscale(qp, (360, 640))


jus = []

while True:
    # 游戏主循环

    for event in pygame.event.get():
        if event.type == QUIT:
            # 接收到退出事件后退出程序
            exit()
        elif event.type == MOUSEBUTTONUP:
            jus.append(event.pos)
            print(jus)

            if(len(jus) == 2):
                s = int(math.sqrt((jus[0][0]-jus[1][0])**2 +
                                  (jus[0][1]-jus[1][1])**2) * 4.176)
                j = "adb shell input swipe 50 50 50 50 " + str(s)
                os.system(j)

                # 延迟两秒钟
                time.sleep(1)

                # 重新加载手机界面
                os.system('adb shell screencap -p /sdcard/a11111.png')
                os.system('adb pull /sdcard/a11111.png')
                qp = pygame.image.load(img_qp).convert()
                qp = pygame.transform.smoothscale(qp, (360, 640))
                # 清空坐标列表
                jus.clear()

    screen.blit(qp, (0, 0))
    # 将背景图画上去

    pygame.display.update()

猜你喜欢

转载自my.oschina.net/bzbc/blog/1803326