实际上,我正在用python实现炸弹人游戏,我想在按键时不断向左向右移动炸弹人。
我想减少随后显示 2D 阵列时终端屏幕上的闪烁。当我不断按下 2D 阵列移动键时,2D 阵列的下部闪烁,这就是我想要减少的。
这是我到目前为止尝试过的:
def printboard():
for x in range(wall1.rows):
for y in range(wall1.columns):
print(arr[x][y],end='')
print('n',end='')
print('n',end='')
类_Getch: ""从标准输入中获取单个字符。 不会回显到屏幕。"" definit(self(: 尝试: self.impl = _GetchWindows(( 除了导入错误: self.impl = _GetchUnix((
def __call__(self): return self.impl()
类_GetchUnix: definit(self(: 导入 tty, 系统
def __call__(self):
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
类_GetchWindows: definit(self(: 导入 MSVCRT
def __call__(self):
import msvcrt
return msvcrt.getch()
getch = _Getch((
如果我正确理解了您的问题,那么这种闪烁是由于执行时间非常快,因此延迟应该可以解决问题。请尝试以下代码行:
import time
{your code here}
time.sleep(0.5) # delays for 0.51 seconds. You can Also Use Float Value.