Beat cookie clicker w/ python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.9 KiB

import pyautogui,sys,threading,logging,time
from random import randint
cookie_location = None
cookie_pos = None
cursor_location = None
cursor_pos = None
grandma_location = None
grandma_pos = None
pyautogui.FAILSAFE = True
def check_failsafe(e):
if type(e) == pyautogui.FailSafeException:
sys.exit(1)
else:
logging.error(str(e))
locations = {}
def check_upgrade(upgrade):
if upgrade not in locations:
try:
logging.info("Searching for " + upgrade)
location = pyautogui.locateOnScreen(upgrade+".png")
if location != None:
locations[upgrade] = location
except Exception as e:
check_failsafe(e)
try:
location = locations[upgrade]
center = pyautogui.center(location)
pyautogui.click(center)
logging.info("Bought a " + upgrade)
except:
pass
upgrades = ["cursor", "grandma", "farm"]
if __name__ == '__main__':
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO,datefmt="%H:%M:%S")
while True:
if cookie_pos == None:
try:
cookie_location = pyautogui.locateOnScreen('cookie.png')
cookie_pos = pyautogui.center(cookie_location)
except:
logging.error("Where the F U C K is the cookie??")
sys.exit(1)
try:
cx, cy = cookie_pos
pyautogui.click(cx,cy)
except Exception as e:
check_failsafe(e)
logging.info("Clicked")
if randint(1,20) == 10:
try:
logging.info("Checking upgrades")
for upgrade in upgrades:
check_upgrade(upgrade)
except Exception as e:
check_failsafe(e)
else:
logging.info("Not checking upgrades")