From 5aec5156ad7756e1ef6834de18207c49c2939eaf Mon Sep 17 00:00:00 2001 From: Plaza521 <89989298+Plaza521@users.noreply.github.com> Date: Wed, 26 Oct 2022 22:40:18 +0300 Subject: [PATCH] remove flicker --- frame.py | 18 ++++++++++++++++-- main.py | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/frame.py b/frame.py index 73f2b92..ec3de3b 100644 --- a/frame.py +++ b/frame.py @@ -1,5 +1,19 @@ from settings import * -import os +from sys import platform + +if platform == "win32": + from ctypes import * + STD_OUTPUT_HANDLE = -11 + STDHANDLE = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) + + class COORDSET(Structure): + _fields_ = [("X", c_long), ("Y", c_long)] + + def _set_cursor_position(x: int, y: int) -> None: + windll.kernel32.SetConsoleCursorPosition(STDHANDLE, COORDSET(x, y)) +else: + def _set_cursor_position(x: int, y: int) -> None: + print(f"\033[{x};{y}H") class Frame: @@ -26,7 +40,7 @@ class Frame: self.matrix[y + line][x + column] = value def show(self) -> None: - os.system("clear||cls") + _set_cursor_position(0, 0) out_string = f"┍{'━' * (self.width * 2)}┑\n" diff --git a/main.py b/main.py index f39097b..7c7fbff 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ from settings import * from player import Player import keyboard as kb from out import Out +from os import system class Game: @@ -27,6 +28,7 @@ class Game: pass def play(self) -> None: + system("clear||cls") while self.running: try: