[+] Move function with bounds
This commit is contained in:
+10
-6
@@ -68,6 +68,14 @@ async def shell(reader: TelnetReaderUnicode, writer: TelnetWriterUnicode):
|
|||||||
# Draw the cat
|
# Draw the cat
|
||||||
print_ascii(ASCII_CAT, x, y)
|
print_ascii(ASCII_CAT, x, y)
|
||||||
|
|
||||||
|
# Move the cat along the x-axis
|
||||||
|
async def move(delta: int):
|
||||||
|
nonlocal x
|
||||||
|
orig = x
|
||||||
|
x = min(max(x + delta, 0), width - ASCII_WIDTH)
|
||||||
|
if x != orig:
|
||||||
|
await update()
|
||||||
|
|
||||||
# Update frame function
|
# Update frame function
|
||||||
async def update():
|
async def update():
|
||||||
while True:
|
while True:
|
||||||
@@ -88,13 +96,9 @@ async def shell(reader: TelnetReaderUnicode, writer: TelnetWriterUnicode):
|
|||||||
# Switch case
|
# Switch case
|
||||||
match inp:
|
match inp:
|
||||||
case '\x1b[C': # Right
|
case '\x1b[C': # Right
|
||||||
x += 1
|
await move(1)
|
||||||
case '\x1b[D': # Left
|
case '\x1b[D': # Left
|
||||||
x -= 1
|
await move(-1)
|
||||||
# case '\x1b[A': # Up
|
|
||||||
# y -= 1
|
|
||||||
# case '\x1b[B': # Down
|
|
||||||
# y += 1
|
|
||||||
case '\x1b': # Escape
|
case '\x1b': # Escape
|
||||||
writer.write('\r\nBye!\r\n')
|
writer.write('\r\nBye!\r\n')
|
||||||
writer.close()
|
writer.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user