2016-12-07 00:46:29 +08:00
|
|
|
import pyautogui
|
|
|
|
import time
|
2016-12-12 23:44:03 +08:00
|
|
|
from ctypes import windll
|
2016-12-14 04:02:33 +08:00
|
|
|
import threading
|
2016-12-07 00:46:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
class lumberjackBot():
|
|
|
|
|
2016-12-08 23:12:27 +08:00
|
|
|
__author__ = "EnriqueMoran"
|
|
|
|
|
|
|
|
def __init__(self, playX, playY, treeX, treeY):
|
|
|
|
self.playX = playX
|
|
|
|
self.playY = playY
|
|
|
|
self.treeX = treeX
|
2016-12-14 04:02:33 +08:00
|
|
|
self.treeY = treeY
|
|
|
|
# Those attributes has been placed here in order to save calcs:
|
2018-05-19 02:44:59 +08:00
|
|
|
self.x = treeX - 22 # Left side branch X location
|
|
|
|
self.y = treeY - 244 # Left side branch Y location
|
|
|
|
self.movement_buffer = ["right"] # First movement
|
2016-12-14 04:02:33 +08:00
|
|
|
|
2016-12-08 23:12:27 +08:00
|
|
|
|
2018-05-19 02:44:59 +08:00
|
|
|
def move(self):
|
|
|
|
speed = 0.17
|
|
|
|
if self.movement_buffer[0] == "left" and len(self.movement_buffer) == 2:
|
2016-12-15 23:14:25 +08:00
|
|
|
pyautogui.typewrite(['left', 'left'], speed)
|
2018-05-19 02:44:59 +08:00
|
|
|
elif self.movement_buffer[0] == "right" and len(self.movement_buffer) == 2:
|
2016-12-15 23:14:25 +08:00
|
|
|
pyautogui.typewrite(['right', 'right'], speed)
|
2018-05-19 02:44:59 +08:00
|
|
|
self.movement_buffer = self.movement_buffer[1:]
|
2016-12-08 23:12:27 +08:00
|
|
|
|
2016-12-12 23:44:03 +08:00
|
|
|
def get_color(self, rgb):
|
|
|
|
r = rgb & 0xff
|
|
|
|
g = (rgb >> 8) & 0xff
|
|
|
|
b = (rgb >> 16) & 0xff
|
|
|
|
return r,g,b
|
|
|
|
|
2018-05-19 02:44:59 +08:00
|
|
|
def get_pixel(self, x, y): # Modify class atribute
|
2016-12-14 04:02:33 +08:00
|
|
|
screen = windll.user32.GetDC(0)
|
|
|
|
rgb = windll.gdi32.GetPixel(screen, x, y)
|
2018-05-19 02:44:59 +08:00
|
|
|
return self.get_color(rgb)
|
2016-12-12 23:44:03 +08:00
|
|
|
|
2016-12-08 23:12:27 +08:00
|
|
|
def play(self):
|
2018-05-19 02:44:59 +08:00
|
|
|
pyautogui.moveTo(self.x, self.y)
|
2016-12-14 04:02:33 +08:00
|
|
|
while True:
|
2018-05-19 02:44:59 +08:00
|
|
|
pixel_color = self.get_pixel(self.x, self.y)
|
|
|
|
if pixel_color == (161, 116, 56):
|
|
|
|
self.movement_buffer.append("right")
|
|
|
|
else:
|
|
|
|
self.movement_buffer.append("left")
|
|
|
|
#print(pixel_color, self.x, self.y, self.movement_buffer)
|
|
|
|
self.move()
|
2016-12-07 00:46:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-05-19 02:44:59 +08:00
|
|
|
print("Running in 3 seconds, minimize this windows. To stop the program drag the mouse to the top-left corner of your screen.")
|
|
|
|
time.sleep(3)
|
2016-12-08 23:12:27 +08:00
|
|
|
playX, playY = pyautogui.locateCenterOnScreen('playButton.png')
|
2016-12-14 04:02:33 +08:00
|
|
|
pyautogui.moveTo(playX, playY)
|
|
|
|
pyautogui.click() # Start the game by pressing play button
|
|
|
|
time.sleep(0.5) # Wait for screen refresh
|
2018-03-12 06:04:59 +08:00
|
|
|
treeX, treeY = playX - 6, playY - 177 # Tree position
|
2016-12-14 04:02:33 +08:00
|
|
|
time.sleep(0.3)
|
|
|
|
print("Im playing... To stop me click on IDLE and press CTRL+F6.")
|
|
|
|
lumberjack = lumberjackBot(playX, playY, treeX, treeY)
|
|
|
|
lumberjack.play() # Game start
|