-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
109 lines (85 loc) · 2.4 KB
/
Copy pathtest.py
File metadata and controls
109 lines (85 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import pyautogui, time, random, keyboard, ctypes, shutil, os
# from screeninfo import get_monitors
from collections import deque
#do position as grid squares
# size of file step
XSTEP = 76
YSTEP = 100
# user screen infos
RES = (1920, 1080)
GRID_BOUNDS = (24,10)
MORE_MON = False
# global game data
TICK = 0.2
snake = deque([(0,2),(0,1),(0,0)])
occupied = set(snake)
APPLE_START = (2,0)
apple = APPLE_START
hx, hy = snake[0] #head cords
# Game logic
def play():
round_setup()
next_move = (0,1)
next_tick = time.monotonic() + TICK
while True:
global hx, hy
hx, hy = snake[0]
if keyboard.is_pressed("q"): break
if keyboard.is_pressed("w") and next_move != (0,1): next_move = (0, -1)
elif keyboard.is_pressed("a") and next_move != (1,0): next_move = (-1, 0)
elif keyboard.is_pressed("s") and next_move != (0,-1): next_move = (0, 1)
elif keyboard.is_pressed("d") and next_move != (-1,0): next_move = (1, 0)
now = time.monotonic()
if now >= next_tick:
if step(next_move): break
next_tick += TICK
time.sleep(0.001)
clean_up()
def step(dir):
global hx, hy
nx = hx + dir[0]
ny = hy + dir[1]
#bounds
if nx > GRID_BOUNDS[0] or ny > GRID_BOUNDS[1] or nx < 0 or ny < 0:
print(hx, hy)
return True
snake.appendleft((nx, ny))
if (nx,ny) != apple:
tail = snake.pop()
move(tail,(nx,ny))
return False
def round_setup():
global apple
# make target
rx = random.randint(2,GRID_BOUNDS[0])
ry = random.randint(1,GRID_BOUNDS[1])
move(APPLE_START,(rx,ry) )
apple = rx, ry
# File logic
# def set_up():
# desktop = os.path
# # display files on the desktop
# # switch folder?
# # switch back?
# for m in get_monitors():
# print()
def clean_up():
reset(snake)
# move(apple, APPLE_START)
print("peace")
def reset(dead_snake, i=0):
if len(dead_snake) > 3:
dead_snake.pop()
reset(dead_snake,i)
if not dead_snake:
return
xy = dead_snake.pop()
move(xy, (0,i))
print(f"{i} {xy}")
reset(dead_snake, i + 1)
def move(origin, dest):
pyautogui.moveTo(origin[0]*XSTEP+10,origin[1]*YSTEP+10)
pyautogui.mouseDown()
pyautogui.moveTo(dest[0]*XSTEP+10, dest[1]*YSTEP+10)
pyautogui.mouseUp()
play()