Új hozzászólás Aktív témák
-
sztanozs
veterán
válasz magortaltos #3312 üzenetére
Itt van non-blocking módban is:
from os import system
from sys import platform
from pynput import keyboard
from pynput.keyboard import Key
from time import sleep
def print_at_x(y, x, text):
print(f"\033[{y};{x}H{text}")
def print_at_w(r, c, s):
h = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
windll.kernel32.SetConsoleCursorPosition(h, COORD(c, r))
prev_codepage = windll.kernel32.GetConsoleOutputCP()
windll.kernel32.SetConsoleOutputCP(65001)
c = s.encode("UTF-8")
windll.kernel32.WriteConsoleA(h, c_char_p(c), len(c), None, None)
windll.kernel32.SetConsoleOutputCP(prev_codepage)
def on_press(key):
global dx, dy, run
if key == keyboard.Key.esc:
run = False
return run
elif key == Key.up:
dx, dy = 0, -1
elif key == Key.left:
dx, dy = -1, 0
elif key == Key.down:
dx, dy = 0, 1
elif key == Key.right:
dx, dy = 1, 0
else:
return
if platform == "linux" or platform == "linux2":
# linux
system('clear')
print_at = print_at_x
elif platform == "darwin":
# MacOS, talán működik itt is
system('clear')
print_at = print_at_x
elif platform == "win32":
# Windows...
from ctypes import *
class COORD(Structure):
pass
STD_OUTPUT_HANDLE = -11
COORD._fields_ = [("X", c_short), ("Y", c_short)]
system('cls')
print_at = print_at_w
print_at(3, 15, 'Próbálj bent maradni a négyzetben!')
for n in range(5,50):
print_at(5, n, '*')
print_at(20, n, '*')
for n in range(5,20):
print_at(n, 5, '*')
print_at(n, 50, '*')
x, y = 25, 7
dx, dy = 0, 0
run = True
print_at(y, x, 'O')
listener = keyboard.Listener(on_press=on_press, suppress=True)
listener.start()
while run:
print_at(y, x, ' ')
x, y = x + dx, y + dy
print_at(y, x, 'O')
if not (5 < x < 50) or not (5 < y < 20):
run = False
sleep(0.1)
print_at(20, 55, 'A játéknak vége !')[ Szerkesztve ]
JOGI NYILATKOZAT: A bejegyzéseim és hozzászólásaim a személyes véleményemet tükrözik; ezek nem tekinthetők a munkáltatóm hivatalos állásfoglalásának...
Új hozzászólás Aktív témák
- Crucial T500 PRO 2 TB M.2 NVME PCI-E 4.0 x4 - Új, Bontatlan, Hűtőbordás - 7400-7000 MBs - Eladó!
- Samsung Galaxy S21+ 5G 256GB, Kártyafüggetlen, 1 Év Garanciával
- Eladó Ipad 9. Generáció 64 GB Wifi Silver
- Apple iPhone 13 Pro Max 128GB, Kártyafüggetlen, 1 Év Garanciával
- ASUS ROG STRIX RTX 2080 SUPER - eladó!
Állásajánlatok
Cég: Ozeki Kft.
Város: Debrecen
Cég: Alpha Laptopszerviz Kft.
Város: Pécs