def main(): l = load() t = Term() x, y = 3, 3 pos = { '\x1b[A': (+1, 0), # up '\x1b[B': (-1, 0), # down '\x1b[C': (0, -1), # right '\x1b[D': (0, +1), # left } playing = True while playing: paint(l) k = t.get() m = pos.get(k) if not m: continue xx, yy = m xx += x yy += y if xx < 0 or xx > 3 or yy < 0 or yy > 3: continue l[x][y] = l[xx][yy] l[xx][yy] = '' x, y = xx, yy playing = not validate(l) paint(l) print("You Win!")
def main(): gt = Term() while True: ch = gt.get() if ch == 'q': break elif ch == 'w': print('\033[1A', end='', flush=True) elif ch == 's': print('\033[1B', end='', flush=True) elif ch == 'a': print('\033[1D', end='', flush=True) elif ch == 'd': print('\033[1C', end='', flush=True) elif ch == 'c': print('\033[2J', end='', flush=True) else: print(ch, end='', flush=True) gt.exit()