我当时正在为恐龙镀铬制作一个跳跃的机器人,但我认为我没有获得色彩的真正价值。如果您需要信息,请告诉我。
代码在这里:
from PIL import ImageGrab, ImageOps
import pyautogui
import time
from numpy import *
class Cordinates():
replayBtn = (370, 405)
dinasur = (165, 512)
def restartGame():
pyautogui.click(Cordinates.replayBtn)
def pressSpace():
pyautogui.keyDown('space')
time.sleep(0.05)
pyautogui.keyUp('space')
def thebox():
box = (157, 416, 201, 432)
image = ImageGrab.grab(box)
grayImage = ImageOps.grayscale(image)
a = array(grayImage.getcolors())
print(a.sum())
def main():
restartGame()
while True:
if thebox() != 951:
pressSpace()
time.sleep(.1)
main()
答案 0 :(得分:0)
您需要从thebox()返回一个值,以便可以在main()的比较中使用它
def thebox():
box = (157, 416, 201, 432)
image = ImageGrab.grab(box)
grayImage = ImageOps.grayscale(image)
a = array(grayImage.getcolors())
return a.sum()
def main():
restartGame()
while True:
if thebox() != 951:
pressSpace()
time.sleep(.1)