Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyautogui
- import time
- import random
- import keyboard
- import pygetwindow as gw
- import win32gui
- import os
- import win32con
- pyautogui.hotkey('win', 'r')
- pyautogui.write('mspaint')
- pyautogui.press('enter')
- time.sleep(2)
- mspaint_window = gw.getWindowsWithTitle('Sans titre - Paint')[0]
- win32gui.SetForegroundWindow(mspaint_window._hWnd)
- time.sleep(0.1)
- win32gui.ShowWindow(mspaint_window._hWnd, win32con.SW_MAXIMIZE)
- pyautogui.hotkey('altleft', 'f')
- pyautogui.press('s')
- pyautogui.write('805')
- pyautogui.press('tab')
- pyautogui.write('607')
- pyautogui.press('enter')
- pyautogui.moveTo(323,66)
- time.sleep(0.05)
- pyautogui.click()
- pyautogui.moveTo(748,97)
- time.sleep(0.05)
- pyautogui.click()
- time.sleep(0.05)
- pyautogui.moveTo(748,255)
- time.sleep(0.05)
- pyautogui.click()
- cell_size = 20
- score = 0
- pyautogui.PAUSE = 0.035
- pause_change = 0.001
- def get_canvas_position():
- paint_win = win32gui.FindWindow(None, 'Sans titre - Paint')
- rect = win32gui.GetWindowRect(paint_win)
- x, y, w, h = rect
- x_offset = 15
- y_offset = 155
- width_offset = 20
- height_offset = 150
- x += x_offset
- y += y_offset
- w -= width_offset
- h -= height_offset
- canvas_width = 800
- canvas_height = 600
- board_width = canvas_width // cell_size
- board_height = canvas_height // cell_size
- return x, y, canvas_width, canvas_height, board_width, board_height
- def draw_game_board(x, y, width, height, cell_size):
- pyautogui.click(x, y)
- pyautogui.dragTo(x + width, y, 0.1, button='left')
- pyautogui.dragTo(x + width, y + height, 0.1, button='left')
- pyautogui.dragTo(x, y + height, 0.1, button='left')
- pyautogui.dragTo(x, y, 0.1, button='left')
- canvas_x, canvas_y, canvas_width, canvas_height, board_width, board_height = get_canvas_position()
- draw_game_board(canvas_x, canvas_y, canvas_width, canvas_height, cell_size)
- player_x = board_width // 2
- player_y = board_height // 2
- player_dx = 1
- player_dy = 0
- trail = [(player_x, player_y)]
- pellet_x = random.randint(1, board_width-2)
- pellet_y = random.randint(1, board_height-2)
- score = 0
- length = 4
- game_over = False
- last_key_press_time = 0
- key_press_interval = 0.1
- def on_key_press(event):
- global player_dx, player_dy, last_key_press_time
- current_time = time.time()
- if current_time - last_key_press_time < key_press_interval:
- return
- last_key_press_time = current_time
- key_name = event.name
- if key_name == 'z' and player_dy != 1:
- player_dx = 0
- player_dy = -1
- elif key_name == 's' and player_dy != -1:
- player_dx = 0
- player_dy = 1
- elif key_name == 'q' and player_dx != 1:
- player_dx = -1
- player_dy = 0
- elif key_name == 'd' and player_dx != -1:
- player_dx = 1
- player_dy = 0
- keyboard.on_press_key("z", on_key_press)
- keyboard.on_press_key("s", on_key_press)
- keyboard.on_press_key("q", on_key_press)
- keyboard.on_press_key("d", on_key_press)
- def on_escape_press(event):
- global game_over
- game_over = True
- keyboard.on_press_key("escape", on_escape_press)
- while not game_over:
- player_x += player_dx
- player_y += player_dy
- if (player_x, player_y) in trail[:-1]:
- game_over = True
- if player_x <= 0 or player_x >= board_width - 0.8 or player_y <= 0 or player_y >= board_height - 0.8:
- game_over = True
- trail.append((player_x, player_y))
- if len(trail) > length:
- last_x, last_y = trail.pop(0)
- last_px = last_x * cell_size + canvas_x
- last_py = last_y * cell_size + canvas_y
- pyautogui.rightClick(last_px, last_py)
- if player_x == pellet_x and player_y == pellet_y:
- while (pellet_x, pellet_y) in trail or pellet_x < 0 or pellet_x >= board_width or pellet_y < 0 or pellet_y >= board_height:
- pellet_x = random.randint(1, board_width-2)
- pellet_y = random.randint(1, board_height-2)
- score += 1
- length += 1
- if pyautogui.PAUSE > 0.001:
- pyautogui.PAUSE -= pause_change
- head_x, head_y = trail[-1]
- head_px = head_x * cell_size + canvas_x
- head_py = head_y * cell_size + canvas_y
- pyautogui.click(head_px, head_py)
- pellet_px = pellet_x * cell_size + canvas_x
- pellet_py = pellet_y * cell_size + canvas_y
- pyautogui.click(pellet_px, pellet_py)
- keyboard.unhook_all()
- pyautogui.alert('Game over! Score: ' + str(score))
- os.system('taskkill /f /im mspaint.exe')
Advertisement
Add Comment
Please, Sign In to add comment