From 6af5e8afc98612f281a7108f7499f3345d5f2a51 Mon Sep 17 00:00:00 2001 From: Megamichi Date: Mon, 6 Nov 2023 20:13:12 +0100 Subject: [PATCH] engine erweitern --- terminal engine/README.md | 0 terminal engine/tengine.py | 54 ++++++++++++++++++++++++++------------ terminal engine/test.py | 24 +++++++---------- 3 files changed, 47 insertions(+), 31 deletions(-) create mode 100644 terminal engine/README.md diff --git a/terminal engine/README.md b/terminal engine/README.md new file mode 100644 index 0000000..e69de29 diff --git a/terminal engine/tengine.py b/terminal engine/tengine.py index 799a05d..c0e31d9 100644 --- a/terminal engine/tengine.py +++ b/terminal engine/tengine.py @@ -1,22 +1,42 @@ from os import get_terminal_size -class tengine(): - tx, ty = get_terminal_size().columns, get_terminal_size().lines - #feld = [[""]*10]*10 - feld = [["","","",],["","","",],["","","",]] +tx = get_terminal_size().columns +ty = get_terminal_size().lines +def genfeld(): + feld = [[' ' for _ in range(tx)] for _ in range(ty)] + return feld +def bg_char(feld,char=str): test = 0 + for a in range(len(feld)): + for b in range(len(feld[0])): + feld[a][b] = test + test = char + return feld + +def strfeld(feld): + back = "" for a in feld: for b in a: - print(test) - b = test - test +=1 - print(feld) - def strfeld(): - back = "" - for a in tengine.feld: - for b in a: - back += b - back += "\n" - return back - def addchar(character=str,position=list): - tengine.feld[2][2] = "a" + back += str(b) + back += "\n" + return back + +def change_char(feld,character=str,position=list): + feld[position[0]][position[1]] = character +def change_block(feld,string=str,position=list): + a = "" + block_len = 0 + for a in string: + if a == "\n": + break + else: + block_len += 1 + print(block_len) + for zeichen in string: + feld[position[0]][position[1]] = zeichen + position[0] += 1 + if position[0]== block_len-1: + position[0] = 0 + return feld + + diff --git a/terminal engine/test.py b/terminal engine/test.py index ab94a1f..438a580 100644 --- a/terminal engine/test.py +++ b/terminal engine/test.py @@ -1,15 +1,11 @@ -#from tengine import tengine -#tengine.addchar("a",[5,5]) -#print(tengine.feld) +import tengine +feld = tengine.genfeld() -feld = [["","","",],["","","",],["","","",]] -feld[1][1] = "a" -test = 0 -for a in feld: - for b in a: - print(test) - b = test - print(b) - test +=1 -feld[1][1] = "a" -print(feld) \ No newline at end of file +block = "halli\nhallo\nfurz" +block2 = """halli +hallo +furz""" + +feld = tengine.bg_char(feld,"#") +feld = tengine.change_block(feld,block2,[3,3]) +print(tengine.strfeld(feld)) \ No newline at end of file