This commit is contained in:
Ksan 2025-12-21 18:30:31 +01:00
parent 34a1709a36
commit 031b7e41cb
5 changed files with 50 additions and 1 deletions

BIN
assets/gameover.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 752 B

BIN
assets/restart.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

BIN
assets/restartt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 B

BIN
assets/tile.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

View File

@ -1,5 +1,9 @@
from enum import IntEnum from enum import IntEnum
import threading
import sys
import keyboard
import time
import pyautogui as pg
class Tile(IntEnum): class Tile(IntEnum):
UNKNOWN = -1 UNKNOWN = -1
FLAG = -2 FLAG = -2
@ -20,10 +24,19 @@ def print_grid(grid):
for row in grid: for row in grid:
print(" ".join(f"[{cell}]" for cell in row)) 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): def loadMap(location: str):
rows = 0 rows = 0
cols = 0 cols = 0
with open("map", "r") as f: with open("map", "r") as f:
for i in f: for i in f:
rows+=1 rows+=1
@ -35,6 +48,9 @@ def loadMap(location: str):
return [rows, cols, map] return [rows, cols, map]
thread = threading.Thread(target=run_kill_switch)
thread.daemon = True
thread.start()
loadedmap = loadMap("map") loadedmap = loadMap("map")
map = loadedmap[2] map = loadedmap[2]
@ -45,5 +61,38 @@ grid = makegrid(loadedmap[0], loadedmap[1])
print_grid(grid) print_grid(grid)
print(map) 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