-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_manager.py
78 lines (61 loc) · 1.97 KB
/
key_manager.py
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
#!/bin/env python3
"""
this is class for handeling keys for playing this Game!
Lets do this :>
we are have Fun Life :D
"""
from readchar import readkey
import push_numbers as p
def true_key(key):
# ('\x03' = ctr + c) and ('\x1a' = ctr + z ) and ('\x18' = ctr + x)
if key == 'Q' or key == 'q' or key == '\x03'\
or key == '\x1a' or key == '\x18': #for quit in the game
return True
# '\x1b[A' = top_arrow
# '\x1b[B' = bot_arrow
# '\x1b[D' = left_arrow
# '\x1b[C' = right_arrow
if key == 'W' or key == 'w'\
or key == 'K' or key == 'k'\
or key == '\x1b[A': #for pushing to Up
return True
if key == 'S' or key == 's'\
or key == 'J' or key == 'j'\
or key == '\x1b[B': #for pushing to Down
return True
if key == 'A' or key == 'a'\
or key == 'H' or key == 'h'\
or key == '\x1b[D': #for pushing to Left
return True
if key == 'D' or key == 'd'\
or key == 'L' or key == 'l'\
or key == '\x1b[C': #for pushing to Right
return True
return False #if not true char
def controler(mat):
"""this function can controling all true key Events"""
c = readkey()
if true_key(c):
if c == 'Q' or c == 'q' or c == '\x03'\
or c == '\x1a' or c == '\x18':
quit()
if c == 'W' or c == 'w'\
or c == 'K' or c == 'k'\
or c == '\x1b[A':
if p.can_pushing_up(mat):
p.pushing_up(mat)
if c == 'S' or c == 's'\
or c == 'J' or c == 'j'\
or c == '\x1b[B':
if p.can_pushing_down(mat):
p.pushing_down(mat)
if c == 'D' or c == 'd'\
or c == 'L' or c == 'l'\
or c == '\x1b[C':
if p.can_pushing_right(mat):
p.pushing_right(mat)
if c == 'A' or c == 'a'\
or c == 'H' or c == 'h'\
or c == '\x1b[D':
if p.can_pushing_left(mat):
p.pushing_left(mat)