diff --git a/assets/gameover.png b/assets/gameover.png new file mode 100644 index 0000000..0d56f2b Binary files /dev/null and b/assets/gameover.png differ diff --git a/assets/restart.PNG b/assets/restart.PNG new file mode 100644 index 0000000..56df256 Binary files /dev/null and b/assets/restart.PNG differ diff --git a/assets/restartt.png b/assets/restartt.png new file mode 100644 index 0000000..f841265 Binary files /dev/null and b/assets/restartt.png differ diff --git a/assets/tile.png b/assets/tile.png new file mode 100644 index 0000000..c2e82d5 Binary files /dev/null and b/assets/tile.png differ diff --git a/src/minesolver.py b/src/minesolver.py index 3a02cfc..0dcf86a 100644 --- a/src/minesolver.py +++ b/src/minesolver.py @@ -1,5 +1,9 @@ from enum import IntEnum - +import threading +import sys +import keyboard +import time +import pyautogui as pg class Tile(IntEnum): UNKNOWN = -1 FLAG = -2 @@ -20,9 +24,18 @@ def print_grid(grid): for row in grid: print(" ".join(f"[{cell}]" for cell in row)) +#kill switch +def run_kill_switch(): + while True: + time.sleep(1) + + if keyboard.is_pressed('b'): + print("Stopping...===========================================") + sys.exit() def loadMap(location: str): rows = 0 cols = 0 + with open("map", "r") as f: for i in f: @@ -35,6 +48,9 @@ def loadMap(location: str): return [rows, cols, map] +thread = threading.Thread(target=run_kill_switch) +thread.daemon = True +thread.start() loadedmap = loadMap("map") map = loadedmap[2] @@ -45,5 +61,38 @@ grid = makegrid(loadedmap[0], loadedmap[1]) print_grid(grid) print(map) +restartImage = r'assets\gameover.png' +tileImage = r'assets\tile.png' + +def restartGame(): + + try: + print("reset") + try: + location = pg.locateOnScreen(restartImage) + + pg.click(location) + print("reset") + except: + print("exception in restart") + return + + except: + return False + +print("loop:") +while(True): + try: + restartGame() + if keyboard.is_pressed('b'): + break + tile = pg.locateOnScreen(tileImage) + + + pg.click(tile) + except: + + print("error neki") + break