【发布时间】:2022-11-18 08:54:15
【问题描述】:
所以,我正在尝试制作一个自动化应用程序
实际上,我正在为 Dino Web Game 制作它
一切都很好,但是! Colors Array 的编号不会改变,我认为是装箱问题
你能用这个框中的正确值指导我吗?
from PIL import ImageGrab, ImageOps
from webbrowser import open_new_tab as new
from pyautogui import keyDown
from time import sleep
from numpy import *
site_url = "https://trex-runner.com/"
dinasour = (692, 494)
def pressSpaceButton():
sleep(0.007)
keyDown('space')
def openGamePage(): # Open Game URL In New Tab
new(site_url)
def restartGame(): # Press Space Button To Start/Restart Game
keyDown('space')
print("Game Has Been Started / Restarted")
def FindCactuses(): # Find Cactuses In Screen
box = ( #(top_left_x, top_left_y, bottom_right_x, bottom_right_y)
dinasour[0] + 30,
dinasour[1],
dinasour[0] + 120,
dinasour[1] + 2
)
image = ImageGrab.grab(box)
grayImage = ImageOps.grayscale(image)
a = array(grayImage.getcolors())
print(a)
return a.sum()
sleep(3) # Wait 3 Seconds
openGamePage()
sleep(5)# Wait 5 Seconds
restartGame()
while True:
FindCactuses()
if FindCactuses != 697:
pressSpaceButton()
它会识别黑色和白色,当它找到黑色时 它会按空格键
【问题讨论】:
标签: python numpy python-imaging-library webbrowser-control pyautogui