Hirdetés
Új hozzászólás Aktív témák
-
No, nem annyira nehéz, csak meg kellett találni a megfelelő modult (meg, hogy windows-on is működjön).
from os import system
from sys import platform
from pynput import keyboard
from pynput.keyboard import Key
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)
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
print_at(y, x, 'O')
def on_press(key):
global x, y
if key == keyboard.Key.esc:
return False
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
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):
return False
with keyboard.Listener(on_press=on_press) as listener:
try:
listener.join()
finally:
listener.stop()
print_at(20, 55, 'A játéknak vége !')
Új hozzászólás Aktív témák
- Eredeti Microsoft Windows 10 / 11 Pro OEM licenc Akciós áron! 64/32 bit Azonnali kézbesítéssel
- LG 25GR75FG - E-Sport Monitor - FHD 360Hz 1ms - NVIDIA Reflex + G-sync - AMD FreeSync - HDR 400
- Xbox One S 1 TB + kontroller 6 hó garancia, számlával!
- BESZÁMÍTÁS! GIGABYTE A520M R5 1400 8GB DDR4 256GB SSD 500GB HDD GTX 1050 Ti 4GB ZALMAN S3 400W
- Bomba ár! Dynabook Portege X40-K - i5-1240P I 16GB I 256SSD I 14" FHD I Cam I W11 I Garancia!
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest


