I'm trying to make a sort of nethack inspired type game and I'm trying to figure out the moving up and down(I know the current code is probably terribly inefficient)(also sorry if this question is formatted weird this is my first ask) import random from pynput.keyboard import Key, Listener import time import os clear = lambda: os.system('cls') floor1 = ["_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_"] floor2 = ["_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_"] floor3 = ["_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_"] floor4 = ["_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_"] floor5 = ["_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_"] def allFloor(): print("".join(floor1)) print("".join(floor2)) print("".join(floor3)) print("".join(floor4)) print("".join(floor5)) char = ("0") spaceAmount = len(floor1) ranStart = random.randint(0, (spaceAmount - 1)) floor1[ranStart] = char charLoc = floor1.index("0") moveLeft = charLoc - 1 moveRight = charLoc + 1 allFloor() def on_release(key): if 'char' in dir(key): charLoc = floor1.index("0") moveLeft = charLoc - 1 moveRight = charLoc + 1 if moveRight >= spaceAmount: moveRight = moveRight - 1 if key.char == "a" and moveLeft >= 0: time.sleep(0.1) floor1[charLoc] = "_" floor1[moveLeft] = char clear() allFloor() elif key.char == "d" and moveRight <= spaceAmount: time.sleep(0.1) floor1[charLoc] = "_" floor1[moveRight] = char clear() allFloor() if key == Key.esc: # Stop listener return False with Listener( on_release=on_release) as listener: listener.join() I was gonna originally just have it check if it's on a specific line and if so when pressing up or down it only goes to the line that is above or below that line Continue reading...