我正在制作一个在命令提示符下运行的游戏,它应该在提示后接受输入。但是,我需要光标与提示保持在同一行。像“输入下一步:[光标停留在这里]”之类的东西。即时通讯使用msvcrt获取输入。
def getinput(game):
display(game)
inp = 21
print("Input next move: ")
while True:
if msvcrt.kbhit():
inp = int(msvcrt.getch().decode("UTF-8"))
while (inp > 8 or inp <0):
print("Choose a number between 0 and 8")
inp = int(msvcrt.getch().decode("UTF-8"))
while (listgame[inp] != "."):
print("Already occupied. Choose an available space")
inp = int(msvcrt.getch().decode("UTF-8"))
break
game[inp]=enemy
print("You played: " + str(inp))
答案 0 :(得分:0)
您可以使用print语句中的end
选项阻止它转到下一行,如下所示:
print("Input next move: ", end="")
这会将光标保持在行的末尾。