Skip to content

Commit fcfc76d

Browse files
authored
v9.3.1 update for stable work snake game
1 parent bfb7347 commit fcfc76d

7 files changed

Lines changed: 26 additions & 22 deletions

File tree

Engine/Console.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def __init__(self):
3030
win32pipe.PIPE_ACCESS_DUPLEX,
3131
win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT,
3232
1,
33-
65536,
34-
65536,
33+
1024 * 1024,
34+
1024 * 1024,
3535
0,
3636
None
3737
)
@@ -60,6 +60,9 @@ def _send_(self, data):
6060
except:
6161
self.enable = False
6262

63+
def _get_(self):
64+
if not self.enable: return
65+
return win32file.ReadFile(self.pipe_in, 1024 * 1024)
6366

6467
def input_init(self):
6568
request = (8).to_bytes(1, "little")
@@ -68,8 +71,8 @@ def input_init(self):
6871
def input_tick(self):
6972
request = (7).to_bytes(1, "little")
7073
self._send_(request)
71-
res = win32file.ReadFile(self.pipe_in, 4096)
72-
return json.loads(res[1][1:].decode())
74+
res = self._get_()
75+
return json.loads(res[1][1:].decode()) if res != None else [{'type': 'exit'}]
7376

7477
def print(self, data):
7578
request = ((2).to_bytes(1, "little")) + data.encode()
@@ -100,7 +103,7 @@ def get_size(self):
100103
request = ((6).to_bytes(1, "little"))
101104
self._send_(request)
102105
time.sleep(1)
103-
res = win32file.ReadFile(self.pipe_in, 4096)
106+
res = self._get_()
104107
if int(res[1][0]) == 1:
105108
return (int(res[1][1]), int(res[1][2]))
106109
else:

Engine/GUIButton.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ def draw(self):
1010

1111
if self.enable:
1212
if self.focused:
13-
self.screen.text(text, self.x, self.y, wordPrefix=self.style["backgroundF"] + self.style["textF"])
13+
self.screen.text(self.x, self.y, text, text_prefix=self.style["backgroundF"] + self.style["textF"])
1414
else:
15-
self.screen.text(text, self.x, self.y, wordPrefix=self.style["background"] + self.style["text"])
15+
self.screen.text(self.x, self.y, text, text_prefix=self.style["background"] + self.style["text"])
1616
else:
17-
self.screen.text(text, self.x, self.y, wordPrefix=self.style["disable"] + self.style["text"])
17+
self.screen.text(self.x, self.y, text, text_prefix=self.style["disable"] + self.style["text"])

Engine/GUILabel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ def __init__(self, screen, style, x=0, y=0, text="", maxLength=40, enable=True,
1010
def draw(self):
1111
"""Отрисовка"""
1212
if self.visible:
13-
self.screen.text(self.text[:self.maxLength], self.x, self.y, wordPrefix=self.style["background"] + self.style["text"])
13+
self.screen.text(self.x, self.y, self.text[:self.maxLength], text_prefix=self.style["background"] + self.style["text"])

Engine/Input.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ class INPUT_RECORD(ctypes.Structure):
5151
_fields_ = [("EventType", SHORT),
5252
("Event", INPUT_UNION)]
5353

54-
#RECORDS ARRAY
55-
class INPUT_RECORD_ARRAY(ctypes.Structure):
56-
_fields_ = [("Records", INPUT_RECORD * 64)]
57-
5854
# -----------------------------------------------
5955

6056
class Input:
@@ -64,7 +60,7 @@ def init(useHotkey=False, lineInput=False, echo=False, resizeEvents=False, mouse
6460
"""Включает получение событий\nПринимает: (bool) useHotkey - использование горячих клавиш, (bool) lineInput - описание отсутствует, (bool) echo - добавление в выходной массив, (bool) resizeEvents - принятие событий изменения размеров окна, (bool) mouseEvents - принятие событий мыши, (bool) insert - включает insert, (bool) quickEdit - выделение мышью, (bool) extended - запрет quickEdit"""
6561
Input.handle = handle or ctypes.windll.kernel32.GetStdHandle(-10)
6662
Input.events = ctypes.wintypes.DWORD()
67-
Input.record = (INPUT_RECORD * 128)()
63+
Input.record = (INPUT_RECORD * 32)()
6864

6965
out = 0
7066

@@ -81,7 +77,7 @@ def init(useHotkey=False, lineInput=False, echo=False, resizeEvents=False, mouse
8177
def tick():
8278
"""Получение и запись событий"""
8379

84-
ctypes.windll.kernel32.ReadConsoleInputExW(Input.handle, ctypes.byref(Input.record), 128, ctypes.byref(Input.events), 2)
80+
ctypes.windll.kernel32.ReadConsoleInputExW(Input.handle, ctypes.byref(Input.record), 16, ctypes.byref(Input.events), 2)
8581

8682
Input.event_count = int(bytes(Input.events)[0])
8783

Engine/Sub_Console.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure):
3535
win32pipe.PIPE_ACCESS_DUPLEX, # доступ на чтение и запись
3636
win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT,
3737
1, # количество экземпляров канала
38-
65536, # размер выходного буфера
39-
65536, # размер входного буфера
38+
1024 * 1024, # размер выходного буфера
39+
1024 * 1024, # размер входного буфера
4040
0, # таймаут на соединение
4141
None # защита по умолчанию
4242
)
@@ -48,7 +48,7 @@ class CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure):
4848

4949
while enable:
5050
try:
51-
message = win32file.ReadFile(pipe_out, 65536)
51+
message = win32file.ReadFile(pipe_out, 1024 * 1024)
5252
except:
5353
enable = False
5454
quit()
@@ -87,7 +87,8 @@ class CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure):
8787

8888
elif command == 7:
8989
data = ((2).to_bytes(1, "little")) + bytes(json.dumps(Input.tick()), "utf-8")
90+
#print(len(data))
9091
win32file.WriteFile(pipe_in, data)
9192

9293
elif command == 8:
93-
Input.init(extended=False, mouseEvents=True, useHotkey=False)
94+
Input.init(extended=True, mouseEvents=True, useHotkey=False)

Engine/Window.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ctypes
22
import os
3+
import time
34
from Engine.Console import Console
45

56
class Window:
@@ -9,12 +10,13 @@ def __init__(self, w:int, h:int):
910
"""Принимает консоль с которой необходимо взаимодействовать"""
1011
self.console = Console()
1112

12-
self.input_init = self.console.input_init
1313
self.input_tick = self.console.input_tick
1414
self.set_title = self.console.set_title
1515
self.set_icon = self.console.set_icon
16-
16+
1717
self.size = self.console.set_size(w, h)
18+
#time.sleep(1)
19+
self.console.input_init()
1820

1921
self.w = w
2022
self.h = h
@@ -141,6 +143,8 @@ def paste(self, window, x=0, y=0):
141143
def text(self, x:int, y:int, text:str="TEXT", text_prefix:str="", symbol_prefix:str="", text_postfix:str="", symbol_postfix:str=""):
142144
"""Текст\nПринимает: (string) text - текст, (int) x - кооридната x, (int) y - коорината y, (string) wordPrefix - префикс перед текстом, (string) symbolPrefix - префикс перед символом, (string) wordPostfix - постфикс после текста, (string) symbolPostfix - постфикс после символа"""
143145
text = str(text)
146+
x = int(x)
147+
y = int(y)
144148
if (x < 0 or y < 0) or (x + len(text) > self.w):
145149
return
146150

Engine/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Многосторонний модуль, для разных задач"""
2-
# version 9.2.1
2+
# version 9.3.1
33

44
# Engine
55
#from Engine.Admin import Admin

0 commit comments

Comments
 (0)