所以,我想做一个自动化的应用程序
其实我是为Dino网络游戏做的
一切正常,但是!颜色数组的编号不变,我认为是装箱问题
您能指导我在此框中输入正确的值吗?
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()
它将识别黑色和白色,当它找到黑色时,它将按空格键
1条答案
按热度按时间owfi6suc1#
如果你只想在某个x,y位置上匹配某个rgb值,那么你可以使用
pyautogui.pixelMatchesColor(x, y, (r, g, b))
,它非常适合这种情况。因此,在您的代码中(请记住,您必须更改x,y值):