Hirdetés
- Google Pixel topik
- Megjöttek Magyarországra a Redmi Note 15-ök, január 22-től ennyiért kaphatók
- Milyen hagyományos (nem okos-) telefont vegyek?
- IDC: 2025-ben a Huawei megnyerte Kínát, az Apple a világot
- iPhone topik
- Okosóra és okoskiegészítő topik
- Xiaomi 15T Pro - a téma nincs lezárva
- Külföldi prepaid SIM-ek itthon
- Így nézhet ki a Huawei Pura 90
- 7600 mAh-s az aksi az iQOO új mobiljában is
Új hozzászólás Aktív témák
-
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 !')
Új hozzászólás Aktív témák
- Dell XPS 13 9300 i7-1065G7 8GB 1000GB FHD+ 500nit! 1 év garancia
- Olcsó Gamer PC-Számítógép! Csere-Beszámítás!I5 6600 /GTX 1650 Super / 16GB DDR4 / 256 SSD + 1TB HDD
- Samsung Galaxy S25 5G 128GB, Kártyafüggetlen, 1 Év Garanciával
- Samsung Galaxy A04s / 4/64GB / Kártyafüggetlen / 12Hó Garancia
- 197 - Lenovo Legion Pro 5 (16IAX10) - Intel Core U7 255HX, RTX 5070
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Laptopműhely Bt.
Város: Budapest


