简体   繁体   中英

pyatuo gui Piano Tiles bot issues

Here is some code I wrote for a piano tiles bot using pyauto gui. I would like it to simply beat the game automatically. Some relevant information: I have double checked all of the pixels that the bot will check to see if the color is black. I do this with the following: pyautogui.pixel(1196,650)[0] == 43. The main issue here is that when I run the program with the piano tiles app open and it will just click the first tile and then click the same square again and lose the game. I also cannot quit the program by pressing q which i dont understand why. I am running this all on my macbook pro and I am new to programming so any advice helps! The piano tiles website I have been using is http://tanksw.com/piano-tiles/ . Thanks in advance!

import time
import keyboard
import random

#Tile 1 position: x=1196 y=650
#Tile 2 position: x=1301 y=650
#Tile 3 position: x=1386 y=650
#Tile 4 position: x=1507 y=650

# while True:q
#     print(pyautogui.position())
#     time.sleep(1)

def click(x,y):
    pyautogui.position(x,y)
    pyautogui.click()
    time.sleep(.01)

while keyboard.is_pressed("q") == False:

    while True:
        pyautogui.moveTo(1196,650)
        if pyautogui.pixel(1196,650)[0] == 43:
            click(1196,650)
        elif pyautogui.moveTo(1301,650):
            if pyautogui.pixel(1301, 650)[0] == 43:
                click(1301, 650)
        elif pyautogui.moveTo(1386,650):
            if pyautogui.pixel(1386, 650)[0] == 43:
                    click(1386, 650)
        elif pyautogui.moveTo(1507,650):
            if pyautogui.pixel(1507, 650)[0] == 43:
                    click(1507, 650)```

To fix the KeyBoard issue, change it to

while True:
    pyautogui.moveTo(1196,650)
    if pyautogui.pixel(1196,650)[0] == 43:
        click(1196,650)
    elif pyautogui.moveTo(1301,650):
        if pyautogui.pixel(1301, 650)[0] == 43:
            click(1301, 650)
    elif pyautogui.moveTo(1386,650):
        if pyautogui.pixel(1386, 650)[0] == 43:
                click(1386, 650)
    elif pyautogui.moveTo(1507,650):
        if pyautogui.pixel(1507, 650)[0] == 43:
                click(1507, 650)

Edit:

    if (keyboard.is_pressed("q")):
        break

For the other issue, try adding a longer delay, this would be added because the blocks don't just disappear, the slide down the grid, therefor the color won't change for a little bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM