Version 1.0

Score record: 367
This commit is contained in:
Enrique Moran 2016-12-06 17:46:29 +01:00 committed by GitHub
parent 3c27e08a4d
commit f043a0f140

44
lumberjackBot.py Normal file
View file

@ -0,0 +1,44 @@
import pyautogui
import time
class lumberjackBot():
__author__ = "EnriqueMoran"
def __init__(self, playX, playY, playerX, playerY):
self.playX = playX
self.playY = playY
self.playerX = playerX
self.playerY = playerY
def move(self, direction):
if direction == "left":
pyautogui.typewrite(['left'])
pyautogui.typewrite(['left'])
elif direction == "right":
pyautogui.typewrite(['right'])
pyautogui.typewrite(['right'])
def play(self):
while(1):
branch = pyautogui.screenshot(region=(playerX, playerY - 85, 1, 1)) # Pixel of tree right side
obstacle = branch.getpixel((0,0))
if obstacle == (161, 116, 56):
self.move("left")
else:
self.move("right")
time.sleep(0.09) # Speed of lumberman
if __name__ == "__main__":
# LUMBERJACK WINDOWS MUST BE CLEAR
playX, playY = pyautogui.locateCenterOnScreen('playButton.png')
pyautogui.moveTo(playX, playY) # Start the game by pressing play button
pyautogui.click()
time.sleep(1)
playerX, playerY = pyautogui.locateCenterOnScreen('player.png') # Recognize position of player
time.sleep(1)
print("Im playing... To stop me click on IDLE window and press ctrl + C")
lumberjackBot(playX, playY, playerX, playerY).play()